Help with Macro

  • Thread starter Thread starter Robby Saputra
  • Start date Start date
R

Robby Saputra

Hi All,

I need help in writing this macro in Excel.
I have a worksheet that asks user to input certain values.
For example
Name:
Address:
The values is kept in B1 and B2

I need to pass this value to a Word Document.
Note that the Word Document is already bookmarked. so It
should be going to the 'spot'

Any suggestion?

Thanks
Robby
 
Untested:


Global objWd as Object, mydoc as Object

Var1 = [B1]
Var2=[B2]

On Error Resume Next
Set ObjWd = GetObject(, "Word.Application")
If Not TypeName(ObjWd) = "Nothing" Then
' ' Word Running
Else
' Word Not Running
NotRunning:
Set ObjWd = CreateObject("Word.Application")
End If
Debug.Print TypeName(ObjWd)
ObjWd.Visible = True
ObjWd.Activate
On Error GoTo 0
Set myDoc = ObjWd.Documents.Open(Blah Blah Blah)

with mydoc
.Selection.GoTo what:=wdGoToBookmark, Name:="your 1st bookmark
name"
.Selection.typetext text:=Var1
'repeat above 2 lines for Var2
end with
 
You might want to replace wdgotobookmark with its actual value:

? wdGoToBookmark
-1

If you have a reference set to word, you don't need to do this, but if not,
you do.

--
Regards,
Tom Ogilvy

Roger Whitehead said:
Untested:


Global objWd as Object, mydoc as Object

Var1 = [B1]
Var2=[B2]

On Error Resume Next
Set ObjWd = GetObject(, "Word.Application")
If Not TypeName(ObjWd) = "Nothing" Then
' ' Word Running
Else
' Word Not Running
NotRunning:
Set ObjWd = CreateObject("Word.Application")
End If
Debug.Print TypeName(ObjWd)
ObjWd.Visible = True
ObjWd.Activate
On Error GoTo 0
Set myDoc = ObjWd.Documents.Open(Blah Blah Blah)

with mydoc
.Selection.GoTo what:=wdGoToBookmark, Name:="your 1st bookmark
name"
.Selection.typetext text:=Var1
'repeat above 2 lines for Var2
end with



--
Hope this gets you started.
Roger
Shaftesbury (UK)







Robby Saputra said:
Hi All,

I need help in writing this macro in Excel.
I have a worksheet that asks user to input certain values.
For example
Name:
Address:
The values is kept in B1 and B2

I need to pass this value to a Word Document.
Note that the Word Document is already bookmarked. so It
should be going to the 'spot'

Any suggestion?

Thanks
Robby
 
Ah, nice one Tom (again)

Thanks
Roger

Tom Ogilvy said:
You might want to replace wdgotobookmark with its actual value:

? wdGoToBookmark
-1

If you have a reference set to word, you don't need to do this, but if not,
you do.

--
Regards,
Tom Ogilvy

Roger Whitehead said:
Untested:


Global objWd as Object, mydoc as Object

Var1 = [B1]
Var2=[B2]

On Error Resume Next
Set ObjWd = GetObject(, "Word.Application")
If Not TypeName(ObjWd) = "Nothing" Then
' ' Word Running
Else
' Word Not Running
NotRunning:
Set ObjWd = CreateObject("Word.Application")
End If
Debug.Print TypeName(ObjWd)
ObjWd.Visible = True
ObjWd.Activate
On Error GoTo 0
Set myDoc = ObjWd.Documents.Open(Blah Blah Blah)

with mydoc
.Selection.GoTo what:=wdGoToBookmark, Name:="your 1st bookmark
name"
.Selection.typetext text:=Var1
'repeat above 2 lines for Var2
end with



--
Hope this gets you started.
Roger
Shaftesbury (UK)







Robby Saputra said:
Hi All,

I need help in writing this macro in Excel.
I have a worksheet that asks user to input certain values.
For example
Name:
Address:
The values is kept in B1 and B2

I need to pass this value to a Word Document.
Note that the Word Document is already bookmarked. so It
should be going to the 'spot'

Any suggestion?

Thanks
Robby
 

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

Back
Top