Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 437
  • Last Modified:

Word 200 VBA Run Time Error 5154

I have written vba code behind word to open a template that has been partially completed from another template. Open a blank template form partially populate and save it with a site specific name. I then want to use the partially complete template form as a master that is opened completely populated and saved using a form button that updates the file name with the date and time and saves as a protected word doc(not template) ...all good and working fine Word 2003 SP3 .... upgrade the 2000 version I hear you say but the user is very happy with 2000 so that is not currently possible. Under 2000 I get the above error with debug highlighting the ActiveDocument SaveAs statement.

What is wrong with the code below ...ideas please!!!
Private Sub CommandButton1_Click()
' Macro recorded 6/11/2008 by Tony Nieroba NBA Computing
'
Dim dd, strClient, strMP As String
 
If ActiveDocument.ReadOnlyRecommended = True Then
   MsgBox "Document Already Saved - Save Button Blocked"
   GoTo endit
End If
 
 
dd = Format(Now, "yymmdd-hhmm")
  'MsgBox dd  ..
strClient = ActiveDocument.CustomDocumentProperties("Client").Value
  'MsgBox strClient
strMP = ActiveDocument.CustomDocumentProperties("MainPath").Value
  'MsgBox strMP
 
    ChangeFileOpenDirectory _
       strMP
    ActiveDocument.SaveAs FileName:=dd & "-" & strClient & "-SPRINKLER SYSTEMS.doc", FileFormat:=wdFormatDocument _
        , LockComments:=False, Password:="", AddToRecentFiles:=True, _
        WritePassword:="BAZZA", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False
 
    ActiveDocument.Close
endit:
End Sub

Open in new window

0
ynot8669
Asked:
ynot8669
  • 3
  • 2
1 Solution
 
Joanne M. OrzechManager, Document Services CenterCommented:
I can't really run the code... but made some very minor modifications....

Private Sub CommandButton1_Click()
' Macro recorded 6/11/2008 by Tony Nieroba NBA Computing
'
Dim dd As Date
Dim strClient, strMP As String
 
If activedocument.ReadOnlyRecommended = True Then
   MsgBox "Document Already Saved - Save Button Blocked"
   GoTo endit
End If
 
 
dd = Format(Now, "yymmdd-hhmm")
  'MsgBox dd  ..
strClient = activedocument.CustomDocumentProperties("Client").Value
  'MsgBox strClient
strMP = activedocument.CustomDocumentProperties("MainPath").Value
  'MsgBox strMP
 
    ChangeFileOpenDirectory _
       strMP
    ActiveDocument.SaveAs FileName:=(dd & "-" & strClient & "-SPRINKLER SYSTEMS.doc"), FileFormat:=wdFormatDocument _
        , LockComments:=False, Password:="", AddToRecentFiles:=True, _
        WritePassword:="BAZZA", ReadOnlyRecommended:=True, EmbedTrueTypeFonts:=False, _
        SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
        False
 
    ActiveDocument.Close
endit:
End Sub

Open in new window

0
 
ynot8669OwnerAuthor Commented:
Yes it was as simple as adding the brackets to make it work ... much appreciated.
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
Excellent.  Please accept the answer so this question may be closed.  Thank you.
0
 
ynot8669OwnerAuthor Commented:
I also found out that If I launch the word template from a link in Excel, I get a the template not a document as expected .... so I now have to find a way around that problem
0
 
Joanne M. OrzechManager, Document Services CenterCommented:
You should just be able to use the documents, add code:

Documents.Add Template:=Options.DefaultFilePath(wdUserTemplatesPath) & "\Document.DOT", newtemplate:=False

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now