Basically, I have a program that is inserting images saved to the hard drive into Word, but first the program must open Word and change the margins. Here is the code relevent to my problems:
-------------------------------------------
Dim WordApp As Word.Application
Dim WordDoc As Word.document
Set WordApp = CreateObject(Class:="Word.Application") 'open microsoft word
With WordApp
.WindowState = wdWindowStateMinimize
.Visible = True
Set WordDoc = .Documents.Add 'create new word doc
'change page margin to accomodate 9 cards per page
With ActiveDocument.PageSetup
.topMargin = InchesToPoints(0.25)
.bottomMargin = InchesToPoints(0.5)
.leftMargin = InchesToPoints(0.25)
.rightMargin = InchesToPoints(0.25)
End With
-----------------------------------------------
The two problems I am experiencing:
1. The first time I run the program, everything works fine. Now, if I do not close down the current Word document (Document1) and run it again, the margins in the second document (Document2) never change. I did some tests and my program still considers Document1 the "ActiveDocument." I do not know how to correct this.
2. The second problem occurs when I close down Microsoft Word after running the program the first time. I run the program again, and at "ActiveDocument.PageSetup" I get Run-time error '462': The remote server machine does not exist or is unavailable. Once again, it's related to the ActiveDocument member, but a different problem entirely.
To sum up, I have to close down Word and restart the program before I can get it to work again. Any help is very much appreciated. Thanks.
-------------------------------------------
Dim WordApp As Word.Application
Dim WordDoc As Word.document
Set WordApp = CreateObject(Class:="Word.Application") 'open microsoft word
With WordApp
.WindowState = wdWindowStateMinimize
.Visible = True
Set WordDoc = .Documents.Add 'create new word doc
'change page margin to accomodate 9 cards per page
With ActiveDocument.PageSetup
.topMargin = InchesToPoints(0.25)
.bottomMargin = InchesToPoints(0.5)
.leftMargin = InchesToPoints(0.25)
.rightMargin = InchesToPoints(0.25)
End With
-----------------------------------------------
The two problems I am experiencing:
1. The first time I run the program, everything works fine. Now, if I do not close down the current Word document (Document1) and run it again, the margins in the second document (Document2) never change. I did some tests and my program still considers Document1 the "ActiveDocument." I do not know how to correct this.
2. The second problem occurs when I close down Microsoft Word after running the program the first time. I run the program again, and at "ActiveDocument.PageSetup" I get Run-time error '462': The remote server machine does not exist or is unavailable. Once again, it's related to the ActiveDocument member, but a different problem entirely.
To sum up, I have to close down Word and restart the program before I can get it to work again. Any help is very much appreciated. Thanks.