I sent this email to Microsoft's VBS Scripting guy, but I never heard back. I want to grab multiple documents (jpegs,word etc,) and automatically insert them into another Word document. The Script guy provided a script to do so, but it didn't work. Thought maybe someone could eye ball the problem. Here's the email I sent to the script guy:
I tried to follow the instructions for inserting multiple files into an MS Word document, but I encountered a problem (actually I found the article in a Nov. '05 article, which also referred to a May '05 article about this).
[ Here's the link: ]
The script ( which is named: mergewrd.vbs) did run, it then opened up MS Word, but then it stops. Nothing happens.
The command line, after running, shows this:
C:\Documents and Settings\Administrator.LAPSYCH\mergewrd.vbs(15, 1) (null): 0x8004103A
The folder's name is 'sun.' In this folder are around 10 jpg's. I know they can be inserted, because I can manually open the jpg's and then insert each one, one by one into MS Word. But obviously, that's tedious, which is why I'm trying this script. I'm not as familiar with the variables that I might need to be changing to fit my computer, but I couldn't identify any unique variables based on your example.
Here's the code, directly taken from your article, but only the file name altered:
Const wdPageBreak = 7
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\sun} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in FileList
objSelection.InsertFile(objFile.Name)
objSelection.InsertBreak(wdPageBreak)
Next
____________________________
So... any idea what's going wrong here???
Thanks for any help,
Dan
I tried to follow the instructions for inserting multiple files into an MS Word document, but I encountered a problem (actually I found the article in a Nov. '05 article, which also referred to a May '05 article about this).
[ Here's the link: ]
The script ( which is named: mergewrd.vbs) did run, it then opened up MS Word, but then it stops. Nothing happens.
The command line, after running, shows this:
C:\Documents and Settings\Administrator.LAPSYCH\mergewrd.vbs(15, 1) (null): 0x8004103A
The folder's name is 'sun.' In this folder are around 10 jpg's. I know they can be inserted, because I can manually open the jpg's and then insert each one, one by one into MS Word. But obviously, that's tedious, which is why I'm trying this script. I'm not as familiar with the variables that I might need to be changing to fit my computer, but I couldn't identify any unique variables based on your example.
Here's the code, directly taken from your article, but only the file name altered:
Const wdPageBreak = 7
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
Set objDoc = objWord.Documents.Add()
Set objSelection = objWord.Selection
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\sun} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in FileList
objSelection.InsertFile(objFile.Name)
objSelection.InsertBreak(wdPageBreak)
Next
____________________________
So... any idea what's going wrong here???
Thanks for any help,
Dan