object variable or With block variable not set on save as

M

Mike

I have the following code which presets the file-save-name to a
collection of bookmarks. If I use the filesave command, it works fine,
but as soon as I use the filesaveas command, I get the "object
variable or With block variable not set" error.

Can anyone see anything strange that I overlooked in my code, or is
this some strange behaviour of word?

'The File save part:

Sub filesave()
Dim oStory As Range

Dim pFileName As String
Dim docTitle As String
Dim docNumber As String
Dim docRev As String

docTitle = ActiveDocument.Bookmarks("Document_title").Range
docNumber = ActiveDocument.Bookmarks("document_number").Range
docRev = ActiveDocument.Bookmarks("revision").Range

pFileName = docNumber & "-" & docRev & "-" & docTitle

With Application.Dialogs(wdDialogFileSaveAs)

.Name = pFileName
.Show

End With

ActiveDocument.save
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing

End Sub

'The File save as part:

Sub filesaveas()

Dim oStory As Range
Dim pFileName As String
Dim docTitle As String
Dim docNumber As String
Dim docRev As String

docTitle = ActiveDocument.Bookmarks("Document_title").Range
docNumber = ActiveDocument.Bookmarks("document_number").Range
docRev = ActiveDocument.Bookmarks("revision").Range

pFileName = docNumber & "-" & docRev & "-" & docTitle

With Application.Dialogs(wdDialogFileSaveAs)

.Name = pFileName
.Show

End With

ActiveWindow.Caption = ActiveDocument.FullName
For Each oStory In ActiveDocument.StoryRanges
oStory.Fields.Update
If oStory.StoryType <> wdMainTextStory Then
While Not (oStory.NextStoryRange Is Nothing)
Set oStory = oStory.NextStoryRange
oStory.Fields.Update
Wend
End If
Next oStory
Set oStory = Nothing

End Sub

I appreciate any help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top