Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Autoinstall a Macro

Posted on 2009-03-30
2
263 Views
Last Modified: 2012-05-06
Hi,

I wrote a simple macro but in order to deliver to the end user i wish instead of me going to each computer, to deliver a cd with a file that will install the macro on the end users computer. Is there a way to do this?
0
Comment
Question by:abitoun
2 Comments
 
LVL 18

Accepted Solution

by:
Rartemass earned 250 total points
ID: 24024776
You could save the macro in the normal.dot file, then replace that file on the end user's PC.

Normal.dot sits at:
C:\Documents and Settings\userID\Application Data\Microsoft\Templates
Where userID is the login ID of the user.
You could also add in into Default user.

The only issue with this is that if they have other setting in the normal.dot the they would be replaced.
0
 
LVL 1

Expert Comment

by:DonQuiyote
ID: 24027058
The idea of using a template is on the right track. However it is not necessary to replace normal.dot. In fact it is not even necessary to use a template if you are using Word 2007 and only wnat users to be able to run the macro manually.

Create a new document and save it as a macro enabled document (.docm). Depending on where the macro is at this time, you may have to copy the code in the VBA editor into a new module, or copy the whole module into a new document.
Add a way for the user to run the macro. Apart from pressing Alt-F8 to bring up a long list of macros, a simple but possibly more elegant way is to write a description and instruction and then add an inline macrobutton field. Press ctl-F9 and then complete the field: {macrobutton yourMacroName A button label}. Right-click on it to collapse the field and then double-click on it to test it.
Or rename/create a macro called autoopen and that will execute automatically. To run it, the user can just open it when needed.
To install your macros you have 3 choices. Place it somewhere in My Documents for manual execution, install it to appear in the New Document dialog, os as a startup template to have it always loaded and available eg if you assigning a shortcut key to it. To automatically install the tempalte, here is a simple solution.
Add the following code to your macro enabled document (.DOCM) that will remain on a CD:

Sub AutoOpen()
' Saves this document as a Word 7 template in the current template path. This must be a a macro enable document (.DOCM). It will simply overwrite the template if openend a second time.
Dim templatePath  As String
Dim templateName As String
    ' palce any other startup processing before the following check
    If ActiveDocument.Type = wdTypeTemplate Then Exit Sub ' this is the template already
    templateName = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 5) ' remove extension
    templatePath = Options.DefaultFilePath(Path:=wdUserTemplatesPath)
    ' Replace with wdStartupPath, and change message below, if the template should always be loaded automatically
    If MsgBox("Press Ok to install this template", vbOKCancel, templateName) = vbOK Then
        ActiveDocument.SaveAs FileName:=templatePath + "\" + templateName, FileFormat:=wdFormatXMLTemplateMacroEnabled, AddToRecentFiles:=False
        MsgBox "The template '" + templateName + "' has been installed and will be available from the New Document menu, under 'My templates'. This document will now be closed. Please restart Word."
        ActiveDocument.Close
    End If
End Sub

Open in new window

0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When creating Microsoft Word-based forms there may be a need to have a form field repeated throughout the whole document. For instance, with a company name, you may want this information repeated automatically throughout the document rather than man…
The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
This video shows the viewer how to set up and create Footnotes in their document. Click on the References tab: Select "Insert Footnote": Type in desired text:
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question