Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy a macro from a Word .DOT into an .RTF file.

Status
Not open for further replies.

DENewkirk

Programmer
Jan 19, 2006
14
US
I'm new to the group, and haven't crafted a search intelligently enough to find what I'm looking for, and haven't the time to look at all of the threads in this forum.

Here's what I'm after: I save an Access report as an .RTF file, intend to copy a macro from Normal.DOT into it, and then run MS Word to open the document. Here's the code I have so far:

Public Function ExportTimesheet() As Boolean
Dim strReportOutput As String

strReportOutput = "C:\Share\Time Sheet.RTF"

docmd.OutputTo acOutputReport, "Time Sheet", acFormatRTF, strReportOutput, False

AttachMacro strReportOutput, "MyMacro"

Call Shell("WINWORD.EXE "/mMyMacro """ & strReportOutput & """", 1)
End Function


This all works fine, except that my sub AttachMacro() is still empty. I found a reference in VBA Help yesterday that had exactly what I wanted, but then I lost it, and have been combing the web and the Object Browser since trying to find the method or statement that will do the trick. All I remember is that it had as arguments 1) an acObjectType, 2) the object's name, 3) source file, 4) destination file, and possibly some optional arguments.

I really do not want to try to hand-code the RTF lines that will embed the macro. Any help would be greatly appreciated.

Don Newkirk
don.e.newkirk@odot.state.or.us
 
This might be a better approach.
[ol]
[li]Create a blank template (*.dot) file that has the macro you want and save it as [tt]Time Sheet.dot[/tt].[/li][li]Spawn a new instance of Word from within Access.[/li][li]Use the Word functionality to Insert the [tt]Time Sheet.rtf[/tt] file into [tt]Time Sheet.dot[/tt][/li][/ol]
I use the *.dot format because Word by default will open this as DocumentX and keeps me from modifing the original template by accident.
Code:
'...
docmd.OutputTo acOutputReport, "Time Sheet", acFormatRTF, strReportOutput, False
Dim objWord As Object
Set objWord = GetObject("C:\Share\Time Sheet.dot")
With objWord
  .Range.InsertFile "C:\Share\Time Sheet.rtf"
  'you can rename, save... the word document here
End With
'...

Hope this helps,
CMP

Funny thing about being unemployed, weekends don't mean quite so much, just means you get to hang out with your working friends. Primus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top