supress fillin field dialog box when doing a save as

M

Michael A

I've got a vbs script that opens a word doc and saves it as a pdf in
word 2007. I'm encountering a problem if I open a word doc that has a
fill-in field. When I do a save as it pops up a dialog box asking for
input for the field. I want to ignore this and just do the save as to
pdf with whatever is already there.

Two things: Can I detect that this has happened? How do I do this?
If I can detect it I can determine how to proceed (I will probably
just toss an error back and move on, but if I can ignore and do the
save as without tossing an error that would be preferable).

Part of the code that is important:

' Open the Word document
on error resume next
Set wdoc = wdocs.Open(sDocFile, False,nil,nil,"?#nonsense@$")

Select Case Err.Number
Case 0
' Let Word document save as PDF
' - for documentation of SaveAs() method,
' see http://msdn2.microsoft.com/en-us/library/bb221597.aspx
wdoc.SaveAs sPDFFile, wdFormatPDF
Select Case Err.Number
Case 0
wdoc.Close WdDoNotSaveChanges
Case Else
WScript.Echo "save_problem"
End Select

Case 5408
WScript.Echo "password"
Case 4198
WScript.Echo "popup"
Case Else
Wscript.Echo "problem"

End Select

wdo.Quit WdDoNotSaveChanges

The SaveAs is not throwing an error or else the Select Case Err.Number
would have detected that and kicked out correctly. So there must be
another way to detect something like this.

Thanks in advance.
 
J

Jay Freedman

Hi Michael,

You might want to try a different course: When you open the document, lock all
its fields. Then do the save as; the locked fields won't fire. When the save is
complete, close the document without saving.

With wdoc
.Fields.Locked = True
.SaveAs sPDFFile, wdFormatPDF
.Close wdDoNotSaveChanges
End With

If the fields could be in text boxes, headers/footers, footnotes, etc., then you
need to be a bit more elaborate, cycling through all the StoryRanges in the
document (http://www.word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all
may benefit.
 
M

Michael A

Hi Michael,

You might want to try a different course: When you open the document, lock all
its fields. Then do the save as; the locked fields won't fire. When the save is
complete, close the document without saving.

    With wdoc
        .Fields.Locked = True
        .SaveAs sPDFFile, wdFormatPDF
        .Close wdDoNotSaveChanges
    End With

If the fields could be in text boxes, headers/footers, footnotes, etc., then you
need to be a bit more elaborate, cycling through all the StoryRanges in the
document (http://www.word.mvps.org/FAQs/Customization/ReplaceAnywhere.htm).

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ:http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroupso all
may benefit.

Thank you,

I'll give that a shot. The one test document that I have does have a
field in the footer. Just looking at the link I don't care what is
actually in the field (and I shouldn't be changing it). The entire
goal is to just save the document as a pdf as-is.
 
M

Michael A

Thank you,

I'll give that a shot.  The one test document that I have does have a
field in the footer.  Just looking at the link I don't care what is
actually in the field (and I shouldn't be changing it).  The entire
goal is to just save the document as a pdf as-is.

In case anyone else needs the answer to this in the future this was my
solution:

Loop through all the stories in the active document, loop through all
the fields in all the stories and unlink the fields:

For Each sr In wdoc.StoryRanges
For Each oField in sr.Fields
oField.Unlink
Next
Next
 

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