Interaction avec d'autres applications

 

Microsoft Access

Avant tout, aller dans Visual Basic Editor, Menu Outils / Références, et s'assurer que la référence "Micrsoft DAO Object Library" soit cochée, puis tester ces macros

'Comment lancer Access

Sub toAutomate()
    Static ac As Access.application
    Set ac = New Access.application
    ac.Visible = true
    ac.OpenCurrentDatabase ("c:\temp\mabase.mdb")
end Sub

A présent vous pouvez utiliser du code pour éxécuter des requêtes, des formulaires, etc
Autre exemple (news)


Ouvrir une base, une table & afficher les valeurs d'un champ

Sub toUseDAO()
    dim db As Database
    dim rs As Recordset
    Set db = Opendatabase("c:\program files\Microsoft Office\Office\Samples\Northwind.mdb")
    Set rs = db.OpenRecordset("products", dbOpendynaset)
    msgbox rs.Fields("Productname").value
end Sub

'Ouvrir une base "Test.mdb" située dans c:\temp, et mettre à jour le champ "NumTel" de la table "téléphone"

Sub MySub()
dim MyDB As Database
dim MyTable as Recordset
Set MyDB = Workspaces(0).Opendatabase("C:\Temp\Test.mdb")
Set MyTable = MyDB.OpenRecordset("téléphone")
with MyTable
      .addNew ![NumTel] = "04-78-31-26-73"
      .Update
end with
MyTable.Close
MyDB.Close
end Sub

Access Automatic name creation : news

Des outils pour passer d'Access à Excel

plutôt chers, semble-t-il !
http://www.acc-technology.com/


Notepad

Ouvrir Notepad

Sub DDEtoBlocNotes()
dim Datarange As range
chan = application.DDEInitiate(app:="NOTEPAD", topic:="C:\abcédaire\test.txt")
Set Datarange = thisworkbook.worksheets("Accueil").range("a1:m1")
Datarange.Copy
application.DDEExecute chan, "[EDITIONCOLLER]"
application.DDETerminate chan
end Sub

Ecrire un fichier texte

Sub WriteTextFile()
Open "c:\windows\desktop\myfile.txt" for Output As #1
Print #1, "This is a line of text."
Print #1, "And here is another."
Close #1
end Sub


Word

Word est-il ouvert ?
dim appWord As Object
On Error Resume next
Set appWord = Getobject(, "Word.application")
if Err.Number <> 0 then 'alors word n'est pas ouvert
Err.Clear 'pour effacer la variable

Word est-il installé !

Declare function findExecutable Lib "shell32.dll" Alias "findExecutableA" (ByVal lpFile As String,
ByVal lpDirectory As String, ByVal lpResult As String) As long

function IsWordInstalled()

Dim rc As long
Dim sDummyFile As String
Dim sDir As String
Dim sFilePath As String * 255
Dim iPos As Integer
sDummyFile = App.Path & "\Dummy.doc"
rc = findExecutable(sDummyFile, sDir, sFilePath)
iPos = InStr(1, sFilePath, "Winword.exe", vbTextCompare)
If iPos <> 0 Then
sFilePath = Left(sFilePath, iPos + 10)
If Dir(sFilePath) <> "" Then
IsWordInstalled = True
End If
End If
End function

Ouvrir Word et désactivez ces macros

Set myobj = CreateObject("Word.Application")
myobj.WordBasic.DisableAutoMacros

Ouvrir Word avec la méthode Shell

Shell pathname:="c:\msoffice\winword\winword.exe C:\data\yourfilenamegoeshere.doc", windowstyle:=1

Ouvrir Word par OLE et exécuter une macro par OLE

dim WRD As New Word.application
WRD.windowstate = wdwindowstateMaximize
WRD.Visible = true/false
WRD.run "Test"
WRD.Quit

Dim oApp As word.Application
On Error Resume Next
Set oApp = GetObject(, "Word.Application.8")
If Err = 0 Then
oApp.Quit
End If
Set oApp = Nothing


Ouvrir un fichier word et y coller des données copiées de la première feuille

Sub test()

Dim myword As New Word.document
Set myword = GetObject("c:\perso\temp\test.doc")

Sheets(1).range("a1:b5").Copy
myword.range.PasteSpecial DataType:=wdPasteRTF
myword.Save
myword.Parent.Quit '<-fermeture de word.
Set myword = Nothing

end sub

Exemples autres pour copier de Word vers Excel ou d'Excel vers Word

Sub Toword()
numcanal = Application.DDEInitiate("WINWORD", "C:\Mes Documents\DOCDDEXL.DOC")
Set plg = Sheets("Feuil1").Range("B1:B3")
Application.DDEPoke numcanal, "essai", plg
DDETerminate (numcanal)
End Sub

Sub FromWord()
numcanal = Application.DDEInitiate("WINWORD", "C:\Mes
Documents\DOCDDEXL.DOC")
Sheets("Feuil1").Select
Range("A2").Value = Application.DDERequest(numcanal, "VersExcel")
DDETerminate (numcanal)
End Sub

Ouvrir un fichier Word et y coller un graphique

Sub macro()
Dim wdApp As Object
Set wdApp = CreateObject("word.application")wdApp.Visible = True 'la variable wdApp est une référence à une instance de Word

wdApp.Documents.Add wdApp.DocumentType:=wdNewBlankDocument
wdApp.Selection.InlineShapes.AddOLEObject ClassType:="Excel.Chart.8", Filename:= "", LinkToFile:=False, DisplayAsIcon:=False
'wdApp.Quit 'pour fermer word
'Set wdApp = Nothing 'pour libérer la variable
End Sub

Ouvrir un document word mais sans afficher Word

Sub A1_091899a()
Dim wordApp As Word.Application
Dim doc As Word.document
Dim rng As Word.range
Rem
Set wordApp = GetObject(, "Word.Application.8")
Set doc = GetObject("e:\temp\docone.doc")
Set rng = doc.Content
With rng.find
.Text = "Now"
.Replacement.Text = "Bow"
.Replacement.Font.Italic = True
.Execute Replace:=wdReplaceAll
End With
doc.Save
Set doc = Nothing
Set wordApp = Nothing
End Sub

Ouvrir un fichier word & récupérer la valeur d'un signet

Sub RecupSignet()
Dim Wd As Word.Application
Set Wd = New Word.Application
With Wd
.Visible = False
.documents.Open ("c:\Mes documents\Test\test.doc")
.Selection.GoTo What:=wdGoToBookmark, Name:="SIGNET1"
MsgBox .Selection.Text
.Quit False
End With
End Sub

Imprimer un document word

Sub PrintWord()
Set myWord=CreateObject("Word.Basic")
myWord.appminimize
myWord.apprestore
chdir "c:\temp\"
myWord.FileOpen "Test.doc"
myWord.FilePrint range:=wdPrintFromto, From:="1", to:="15"
end Sub

Ou encore, pour l'imprimer en entier

Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, _
ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Sub FaisonsBref()
ShellExecute 0, "print", "D:\MonDir\MonFichier.doc", "", "", 0
End Sub

Cet exemple montre comment ajouter un document Word lié à une feuille de calcul.

Set mydocument = Worksheets(1)
mydocument.Shapes.AddOLEObject Left:=100, Top:=100, Width:=200, Height:=300, FileName:="c:\my documents\testing.doc", link:=True

Cet exemple montre comment ajouter un nouveau bouton de commande à mydocument.

Set mydocument = Worksheets(1)
mydocument.Shapes.AddOLEObject Left:=100, Top:=100, _
Width:=100, Height:=200, _
ClassType:="Forms.CommandButton.1"


Boucler sur les fichiers Word liés dans un classeur Excel
De: Barrett G., Objet: Re: Working with an embedded Word document, Date : mardi 19 septembre 2000 19:08

Sub Riskcont()
Dim MyWord As Word.Document, embeddedobject, sht
Dim sheetnames() As String, sheetcount As Integer, i As Integer

On Error Resume Next
sheetcount = ActiveWorkbook.Sheets.Count
ReDim sheetnames(1 To sheetcount)

For i = 1 To sheetcount: sheetnames(i) = ActiveWorkbook.Sheets(i).Name: Next i

For i = 1 To sheetcount
Set sht = ActiveWorkbook.Sheets(sheetnames(i))

For Each embeddedobject In sht.OLEObjects
'loop through objects in sheet to make sure you have the word document

If embeddedobject.ProgId = "Word.Document.8" Then
Set MyWord = embeddedobject.Object
MyWord.Select
Selection.Activate
Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
Selection.TypeText Text:="01"
End If

Debug.Print MyWord.Name
Debug.Print sht
Next embeddedobject

Next i

Set MyWord = Nothing

End Sub


Créer une enveloppe sous Word

Sub createletter()
Dim w As Object
Set w = CreateObject("word.basic")
With w
.filenew template:="quoteletter.dot"
.editselectall
.formatfont Points:=12, Underline:=0, Font:="arial"
.filesaveas Name:="c:\Business Maker\PDT\CIF
sheets\wordtest.doc"
End With
End Sub


Powerpoint

Comme il n'y a pas de forum PowerPoint en Français, je vous annonce que Microsoft a mis sur son site web un correctif de vulnérabilité des scripts HTML; pour PowerPoint 97. Le correctif est daté du 25 juillet 2000. http://officeupdate.microsoft.com/canada/french/downloadcatalog/dldpowerpoin t.asp#9798

Copier un graphique dans Powerpoint

Here's an example where I use an Excel 97 VBA macro to copy a chart from Excel into a PowerPoint Slide. Hope you find it useful.

Sub Chart_Into_Ppt()
Set PPT = New PowerPoint.Application
With PPT
.Visible = True
.Activate
End With
My_Pres = thisworkbook.Path & "\spcorch.ppt"
Set Pres = PPT.Presentations.Open(My_Pres)
For x = 1 To 3
Set Out_Sh = Workbooks("SPC_1.XLS").sheets(x + 1)
Set My_Chart = Out_Sh.ChartObjects("X_Chart")
Title_Text = Out_Sh.[F201]
PPT.Windows(1).View.GotoSlide x
With Pres
.Slides(x).Shapes(1).TextFrame.Textrange.Characters.Text = Title_Text
.Slides(x).Shapes(2).Select
End With
My_Chart.CopyPicture Appearance:=xlPrinter, Format:=xlPicture
PPT.Windows(1).View.Paste
Next
End Sub

Comment copier une plage d'Excel dans une diapo PowerPoint en tant qu'image en Vba : news
Autre exemple : news

Lancer un fichier powerpoint

Private Sub LancerDiaporamaPowerpoint()
Dim Ppt_file As Object
On Error GoTo s
AppActivate "Microsoft PowerPoint"
GoTo n
s:
Application.ActivateMicrosoftApp (xlMicrosoftPowerPoint)
n:
Set Ppt_file = GetObject("c:\mes documents\fichierppt.ppt")
Ppt_file.SlideShowSettings.Run
End Sub

 

Autocad : Où avoir des infos dessus ???

- S'abonner au forum : comp.cad.autocad (en anglais) ou news : news://adesknews.autotodesk.com
- S'inscrire a une liste de dissusion francophone sur Autocad : http://www.chez.com/spaso/acad/acad.html

 

Lotus Notes

Essayez de chercher ici :

http://www.notes.net/today.nsf/lookup/com_access
http://www.lotus.com/developers/devbase.nsf/homedata/article?OpenDocumen t&url=/developers/devbase.nsf/homedata/homecom


Q148240 XL: Visual Basic Equivalents for Lotus Macro Commands (WE1277)
http://support.microsoft.com/support/kb/articles/Q148/2/40.ASP
Page à lire 1, Page à lire 2

Conversion de carnet d'adresses : classeur à télécharger

Oracle

Bien sûr des sociétés vendent des produits qui servent à mettre à jour les tables d'oracle à partir d'excel, x comme le produit Oraxcel de Gerrit Jan Linker - voir http://members.aol.com/gjlinker/ . En utilisant la DAO et les MS Query (menu données, données externes), vous devez pouvoir consulter voire modifier les tables oracle. (voir aussi http://www.oraxcel.com/)

Comment lancer une procédure stockée sur une base de données ORACLE (ou INFORMIX) depuis VBA sous Excel.
Je n'ai pas vérifié la pertinence des liens ci-dessous mais c'est déjà des pistes pour vous.
http://www.rci-info.fr/rta/RTAPF.htm
http://www.oraxcel.com/ dont http://www.oraxcel.com/projects/sqlxl/
http://www.rumken.com/ioug2000/Paper951.htm (en anglais)
http://www.dataeasier.com/ (en anglais)

Pour trouver comment accéder à différentes bases : http://www.able-consulting.com/tech.htm

Cet exemple devrait marcher pour récupérer des infos d'une base oracle

Sub GetOracleList(Valg As Long)

Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim fld As ADODB.Field
Dim Sok As String

Sok = "SELECT PROG_ID, TITTEL" & Chr(10)
Sok = Sok & "FROM ORADUMMY.PROG" & Chr(10)
Sok = Sok & "WHERE PROG_ID = " & Valg

'here it is:
cnn.Open "Driver={Microsoft ODBC for Oracle};" & "Server=ORADUMMY.world;" & "Uid=HaraldAtWork;" & "Pwd=NiceTryHarald;"
rst.Open Sok, cnn, adOpenForwardOnly, adLockReadOnly

Sheets(1).Cells(2, 1).CopyFromRecordset rst
rst.Close

End Sub

 

Visual C++

HOWTO: Build an Add-in (XLL) for Excel Using Visual C++ http://support.microsoft.com/support/kb/articles/Q178/4/74.ASP

 

Winzip

vous pouvez voir les articles suivants :
http://www.planet-source-code.com/xq/ASP/txtCodeId.4678/lngWId.1/qx/vb/scrip ts/ShowCode.htm
http://www.planet-source-code.com/xq/ASP/txtCodeId.4696/lngWId.1/qx/vb/scrip ts/ShowCode.htm

Voici comment j'ai procédé pour compacter une base sans consulter les articles ci-dessus

Dim ShellString As String
ShellString = "E:\Program Files\WinZip\WINZIP32.EXE" & " -a " & Chr(34) & "CheminCompletAlaNouvelleArchiveACreer" & Chr(34) & " " & Chr(34) & "CheminCompletAuFichieraArchiver" & Chr(34)
variablequelconque = Shell(ShellString, vbMinimizedNoFocus)

Vous pouvez trouver un utilitaire sympathique sur Excel Downloads (voir les Goodies), il fait appel à une librairie de fonction, permettant de manipuler Winzip.

 

Delphi

Un exemple de manipulation d'excel avec Delphi : news

 

Outlook

Cf xl_et_le_web.htm


Adobe Acrobat Reader

Il existe des produits sur Internet qui permettent d'imprimer des documents au format PDT, comme Win2PDF.
Au cas où vous avez Acrobat Writer sur votre poste, vous pouvez essayez la macro suivante : news

Là encore, dans la base de téléchargements d'Excel Downloads, vous trouverez une démonstration de manipulation d'Adobe à travers un formulaire (userform).