Discussion:
autoinstall of a tempate (SaveAs FileFormat:=wdFormatTemp) ERROR
(too old to reply)
Peter
2005-05-01 11:17:04 UTC
Permalink
Hello everyone,

I am working on distributing a VBA utility an want to distribute in the
easest possible way for people to install and use.

I would like to distribute it as a single Word .DOC file that will contain
both the documentation and the VBA. The document will contain buttons to
install the code in the .../WORD/STARTUP folder and also uninstall it. The
utilility will be launched by a toolbar button.

The fall back method (which is working) to distribute it as a .DOC (with
document and Install button) and a seperate .DOT file.

The install code is given below but there is a problem (isn't there always).

1. It will run correctly if I click the RUN button in the VBA editor but if
I click a button in the document I get a "Runtime eror 4198. Cpommand failed"

2. Sometimes, when Word is restarted I get a message saying that the
template in the STARTUP folder is "not valid"

Does anyone have any suggestions on how to get around this problem so I
distribute a single file.

Thanks in anticipation of receiving lots of helpful suggestions,
Peter
http://members.dodo.com.au/bakerevans/

------
Sub install()
Dim destfile As String
Dim sourceFile As String
Dim thisfile As String
Dim theMessage

theMessage = "Do you want to install Word Purge?" & vbCrLf
If MsgBox(theMessage, vbYesNo) = vbYes Then

'name of this file
thisfile = Application.ActiveDocument.FullName

destfile = Options.DefaultFilePath(wdStartupPath) & _
Application.PathSeparator & "Word Purge.dot"

sourceFile = Application.ActiveDocument.Path & _
Application.PathSeparator & "Word Purge.dot"

ActiveDocument.SaveAs FileName:=destfile, _
FileFormat:=wdFormatTemplate

End If
end sub
Tom Winter
2005-05-02 13:14:06 UTC
Permalink
As for problem #1, perhaps you should consider using a macrobutton field
instead of a commandbar button. That's what I use to start macros contained
within a document. Here's a good article on it:

http://www.addbalance.com/usersguide/parts/macrobutton_fields.htm

Also, your code contains some unused code. You don't need to lines for
thisfile or sourcefile, since you don't use those variables.
--
Tom Winter
Post by Peter
Hello everyone,
I am working on distributing a VBA utility an want to distribute in the
easest possible way for people to install and use.
I would like to distribute it as a single Word .DOC file that will contain
both the documentation and the VBA. The document will contain buttons to
install the code in the .../WORD/STARTUP folder and also uninstall it. The
utilility will be launched by a toolbar button.
The fall back method (which is working) to distribute it as a .DOC (with
document and Install button) and a seperate .DOT file.
The install code is given below but there is a problem (isn't there always).
1. It will run correctly if I click the RUN button in the VBA editor but if
I click a button in the document I get a "Runtime eror 4198. Cpommand failed"
2. Sometimes, when Word is restarted I get a message saying that the
template in the STARTUP folder is "not valid"
Does anyone have any suggestions on how to get around this problem so I
distribute a single file.
Thanks in anticipation of receiving lots of helpful suggestions,
Peter
http://members.dodo.com.au/bakerevans/
------
Sub install()
Dim destfile As String
Dim sourceFile As String
Dim thisfile As String
Dim theMessage
theMessage = "Do you want to install Word Purge?" & vbCrLf
If MsgBox(theMessage, vbYesNo) = vbYes Then
'name of this file
thisfile = Application.ActiveDocument.FullName
destfile = Options.DefaultFilePath(wdStartupPath) & _
Application.PathSeparator & "Word Purge.dot"
sourceFile = Application.ActiveDocument.Path & _
Application.PathSeparator & "Word Purge.dot"
ActiveDocument.SaveAs FileName:=destfile, _
FileFormat:=wdFormatTemplate
End If
end sub
Chuck
2005-06-13 12:19:03 UTC
Permalink
Hi Peter

You may be getting the "Command failed" error because the code behind the
toolbar button isn't explicit enough to identify the macro in your document.
Try using Application.Run "YourMacro" instead of just the macro name.

You're getting the "not valid" error because for some reason your document
isn't being saved as a template.

Have you considered distributing it as a .dot instead of a .doc file? You
can put the documentation in the .dot file as easily as in a .doc.

HTH
Chuck
Post by Peter
Hello everyone,
I am working on distributing a VBA utility an want to distribute in the
easest possible way for people to install and use.
I would like to distribute it as a single Word .DOC file that will contain
both the documentation and the VBA. The document will contain buttons to
install the code in the .../WORD/STARTUP folder and also uninstall it. The
utilility will be launched by a toolbar button.
The fall back method (which is working) to distribute it as a .DOC (with
document and Install button) and a seperate .DOT file.
The install code is given below but there is a problem (isn't there always).
1. It will run correctly if I click the RUN button in the VBA editor but if
I click a button in the document I get a "Runtime eror 4198. Cpommand failed"
2. Sometimes, when Word is restarted I get a message saying that the
template in the STARTUP folder is "not valid"
Does anyone have any suggestions on how to get around this problem so I
distribute a single file.
Thanks in anticipation of receiving lots of helpful suggestions,
Peter
http://members.dodo.com.au/bakerevans/
------
Sub install()
Dim destfile As String
Dim sourceFile As String
Dim thisfile As String
Dim theMessage
theMessage = "Do you want to install Word Purge?" & vbCrLf
If MsgBox(theMessage, vbYesNo) = vbYes Then
'name of this file
thisfile = Application.ActiveDocument.FullName
destfile = Options.DefaultFilePath(wdStartupPath) & _
Application.PathSeparator & "Word Purge.dot"
sourceFile = Application.ActiveDocument.Path & _
Application.PathSeparator & "Word Purge.dot"
ActiveDocument.SaveAs FileName:=destfile, _
FileFormat:=wdFormatTemplate
End If
end sub
Loading...