Bonjour,
Dans son message, < UnkleVo > écrivait :
In this message, < UnkleVo > wrote:
|| We need to add one line of VBA script to 350 word documents.
||
|| Is there any way to automate this?
||
|| For example looping through all this docs from DOTNET program and
|| access and modify VBA script that way..
||
Here is an code sample to get you going:
(This a sample to programmatically create a macro procedure, but you can
easily modify to edit an existing macro instead.)
'_______________________________________
Sub CreateMacro()
'Originally posted by Dave Lett
Dim strVBProj As String
Dim strVBMod As String
' Specify the project name for your template or document
' and module in the project to store the macro.
strVBProj = "Project"
strVBMod = "Module1"
On Error GoTo cmErrHandler
With VBE.VBProjects(strVBProj).VBComponents(strVBMod).CodeModule
.DeleteLines Startline:=1, Count:=.CountOfLines
' you might want to investigate the addfromfile method
' you might want to investigate the replaceline method
.InsertLines Line:=1, String:="Sub MyMacro"
.InsertLines Line:=2, String:=" ' Created by code."
.InsertLines Line:=3, String:="End Sub"
End With
cmErrHandler:
If Err.Number <> 0 Then
MsgBox "Error: Specified Project and/or Module does not exist."
End If
End Sub
'_______________________________________
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site:
http://www.word.mvps.org