C
Compass Rose
Working in Word 2000 and being inexperienced in VBA, I have recorded/written
a macro to perform some file tasks. I am not getting the results I am looking
for. I hope someone can help.
I have read about the suggestion of SETting a Document variable when opening
and working with several documents at the same time. I am not sure of the
syntax to define the 2 variables to make it work the way I want.
When the Unlink Fields is executed, it unlinks the fields in both open
documents, whereas I just want it to unlink the fields in the oDoc_New
document. The same is true of the Close. I want it to only close the oDoc_New
document.
I have been reading on this message board about the inadvisability of using
the Selection method over the Range method. My code is posted below and I
would appreciate some sample code suggestions of how to accomplish the tasks
that are currently using Selection, using Range instead.
The bookmark "NextBusiDay" contains fields that calculate a future date
using macropod's excellent work. The code is as follows:
Dim strNextDay As String, strTodayFileName As String, strNextDayFileName _
As String
Dim oDoc As Document, oDoc_New As Document
Application.ScreenUpdating = False
Set oDoc = ActiveDocument
With oDoc
.Save
strTodayFileName = oDoc.FullName
End With
Selection.WholeStory
Selection.Font.Hidden = False
Selection.GoTo What:=wdGoToBookmark, Name:="NextBusiDay"
With oDoc.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.Fields.Update
Selection.Copy
strNextDay = Selection.Text
Selection.Font.Hidden = True
strNextDayFileName = Left(strTodayFileName, Len(strTodayFileName) - 17) _
& strNextDay & ".doc"
oDoc.SaveAs FileName:=strNextDayFileName
Set oDoc_New = Documents.Open(strTodayFileName)
Selection.WholeStory
Selection.Fields.Unlink
Documents.Save
Documents.Close
Application.ScreenUpdating = True
Set oDoc_New = Nothing
Set oDoc = Nothing
I was also wondering what is the difference between hidden text and a hidden
bookmark? Could I use the hidden bookmark instead of the hidden text in this
case?
TIA
David
a macro to perform some file tasks. I am not getting the results I am looking
for. I hope someone can help.
I have read about the suggestion of SETting a Document variable when opening
and working with several documents at the same time. I am not sure of the
syntax to define the 2 variables to make it work the way I want.
When the Unlink Fields is executed, it unlinks the fields in both open
documents, whereas I just want it to unlink the fields in the oDoc_New
document. The same is true of the Close. I want it to only close the oDoc_New
document.
I have been reading on this message board about the inadvisability of using
the Selection method over the Range method. My code is posted below and I
would appreciate some sample code suggestions of how to accomplish the tasks
that are currently using Selection, using Range instead.
The bookmark "NextBusiDay" contains fields that calculate a future date
using macropod's excellent work. The code is as follows:
Dim strNextDay As String, strTodayFileName As String, strNextDayFileName _
As String
Dim oDoc As Document, oDoc_New As Document
Application.ScreenUpdating = False
Set oDoc = ActiveDocument
With oDoc
.Save
strTodayFileName = oDoc.FullName
End With
Selection.WholeStory
Selection.Font.Hidden = False
Selection.GoTo What:=wdGoToBookmark, Name:="NextBusiDay"
With oDoc.Bookmarks
.DefaultSorting = wdSortByName
.ShowHidden = True
End With
Selection.Fields.Update
Selection.Copy
strNextDay = Selection.Text
Selection.Font.Hidden = True
strNextDayFileName = Left(strTodayFileName, Len(strTodayFileName) - 17) _
& strNextDay & ".doc"
oDoc.SaveAs FileName:=strNextDayFileName
Set oDoc_New = Documents.Open(strTodayFileName)
Selection.WholeStory
Selection.Fields.Unlink
Documents.Save
Documents.Close
Application.ScreenUpdating = True
Set oDoc_New = Nothing
Set oDoc = Nothing
I was also wondering what is the difference between hidden text and a hidden
bookmark? Could I use the hidden bookmark instead of the hidden text in this
case?
TIA
David