How to insert a VB macro in word doc (programatically)

S

shokiegupta

Can anyone please help me with this? I am trying to insert a VB macro
(2 line code) in MS word documnet (programatically!!).

Here is what i am doing:
Dim odoc As Word.Document
Set wordApp = New Word.Application
With wordApp
Set odoc = .Documents.Open(App.Path & "\sample.doc", , False)
<something needs to be done here>
odoc.Save
odoc.Close
End With
Set odoc = Nothing
Set wordApp = Nothing

So dont know how to insert macro code here in this word document
(programatically).

Any help would be appriciated! Thanks!
 
B

Baconbutty

Can anyone please help me with this? I am trying to insert a VB macro
(2 line code) in MS word documnet (programatically!!).

Here is what i am doing:
Dim odoc As Word.Document
Set wordApp = New Word.Application
With wordApp
Set odoc = .Documents.Open(App.Path & "\sample.doc", , False)
<something needs to be done here>
odoc.Save
odoc.Close
End With
Set odoc = Nothing
Set wordApp = Nothing

So dont know how to insert macro code here in this word document
(programatically).

Any help would be appriciated! Thanks

Hi, I am a pure amateur at this (programming is not my day job), so I
am not sure if this helps, but I am currently looking at the VBProject
object.

Accessible from NormalTemplate.VBProject, or ActiveDocument.VBProject.

This seems to offer access to code modules.

I am currently looking at something similar, where I have an external
script that is automating word and programmatically setting up a
toolbar and custom VB procedures. Not got it working yet.

Regards

Julian Turner
 

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