pass params 2 WORD

  • Thread starter Ivan \(CLIPERNET.COM\)
  • Start date
I

Ivan \(CLIPERNET.COM\)

Hi there! thank you for reading me!!

My questions is simple:

Is it possible to open a Word Document passing some parameters in order to
use them as field values?

I am thinking in something like document.doc?param1=car&param2=dog

I would be gratefull if someone can help me in this matter.

Ivan.
 
C

Chuck

You can't open a document and pass parameters, but you can run a macro with
parameters that opens a document and then uses the parameters to supply
information to the document. For instance, if you have a document with
BookmarkA and BookmarkB the following code would open the document and insert
the parameters into the appropriate locations. Following code assumes the
document you're filling in has BookmarkA and BookmarkB, and you should change
the file names as necessary. You don't have to use bookmarks, you can use
fields or any other location you wish - bookmarks are just for illustration
purposes.

HTH

Sub SupplyParameters()

'You call the macro and supply the parameters
'defined in the macro you're calling --
'see below
FillInDoc "car", "dog"

End Sub

Sub FillInDoc(ByVal strBkA As String, ByVal strBkB As String)

Dim docDoc As Document

Set docDoc = Documents.Open("yourdoc.doc")

With docDoc
If .Bookmarks.Exists("BookmarkA") Then
.Bookmarks("BookmarkA").Range.Text = "car"
End If
If .Bookmarks.Exists("BookmarkB") Then
.Bookmarks("BookmarkB").Range.Text = "dog"
End If
End With

docDoc.SaveAs "yournewdoc.doc"
docDoc.Close

Set docDoc = Nothing

End Sub
 
I

Ivan

Thank you Chuck!

Ivan

Chuck said:
You can't open a document and pass parameters, but you can run a macro with
parameters that opens a document and then uses the parameters to supply
information to the document. For instance, if you have a document with
BookmarkA and BookmarkB the following code would open the document and insert
the parameters into the appropriate locations. Following code assumes the
document you're filling in has BookmarkA and BookmarkB, and you should change
the file names as necessary. You don't have to use bookmarks, you can use
fields or any other location you wish - bookmarks are just for illustration
purposes.

HTH

Sub SupplyParameters()

'You call the macro and supply the parameters
'defined in the macro you're calling --
'see below
FillInDoc "car", "dog"

End Sub

Sub FillInDoc(ByVal strBkA As String, ByVal strBkB As String)

Dim docDoc As Document

Set docDoc = Documents.Open("yourdoc.doc")

With docDoc
If .Bookmarks.Exists("BookmarkA") Then
.Bookmarks("BookmarkA").Range.Text = "car"
End If
If .Bookmarks.Exists("BookmarkB") Then
.Bookmarks("BookmarkB").Range.Text = "dog"
End If
End With

docDoc.SaveAs "yournewdoc.doc"
docDoc.Close

Set docDoc = Nothing

End Sub
 

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