Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Passing a variable from Excel to Word

My routine below works beautifully, I would like to pass the variable
"NumToPrint" to a Word macro called "Print10", so I can use it there to
determine the number of copies I should print.
Does anyone know how can I accomplish this?

Public NumToPrint As Integer
Sub PrintPostInstructions()
Dim oWord As Object
NumToPrint = Cells(1, 6)
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = CreateObject("Word.Application")
End If
On Error GoTo 0
oWord.Application.Visible = True
oWord.Application.Activate
With oWord
..Documents.Open Filename:="E:\Documents\Angelika's Studio\Permanent
Make-Up\Post Instructions.doc", ReadOnly:=False
..Application.Run MacroName:="Normal.NewMacros.Print10"
oWord.Quit
End With
Set oWord = Nothing
End Sub


Thanks in advance,
Rocky McKinley



  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 399
Default Passing a variable from Excel to Word

Rocky: You might explore Word's document variables (see Word VBA Help and
do a Google search through *word* groups). I've never used them before, but
it appears that you can create a new named variable resident in the
document, populate it, and reference it.

In this case, you might be able to create a "Temp" variable in the document
you open and populate it with your NumToPrint result. Then have your Word
macro call this variable for use in the macro. The last line of the macro
could destroy the variable, or close without saving changes.

Shot in the dark.
Ed

"Rocky McKinley" wrote in message
...
My routine below works beautifully, I would like to pass the variable
"NumToPrint" to a Word macro called "Print10", so I can use it there to
determine the number of copies I should print.
Does anyone know how can I accomplish this?

Public NumToPrint As Integer
Sub PrintPostInstructions()
Dim oWord As Object
NumToPrint = Cells(1, 6)
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = CreateObject("Word.Application")
End If
On Error GoTo 0
oWord.Application.Visible = True
oWord.Application.Activate
With oWord
.Documents.Open Filename:="E:\Documents\Angelika's Studio\Permanent
Make-Up\Post Instructions.doc", ReadOnly:=False
.Application.Run MacroName:="Normal.NewMacros.Print10"
oWord.Quit
End With
Set oWord = Nothing
End Sub


Thanks in advance,
Rocky McKinley





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Passing a variable from Excel to Word

Rocky,

..Application.Run "Print10",NumToPrint

will pass the the value of NumToPrint to your macro

Your word macro will be "Sub Print10 (Num)"


HTH

"Rocky McKinley" wrote:

My routine below works beautifully, I would like to pass the variable
"NumToPrint" to a Word macro called "Print10", so I can use it there to
determine the number of copies I should print.
Does anyone know how can I accomplish this?

Public NumToPrint As Integer
Sub PrintPostInstructions()
Dim oWord As Object
NumToPrint = Cells(1, 6)
On Error Resume Next
Set oWord = GetObject(, "Word.Application")
If Err Then
Set oWord = CreateObject("Word.Application")
End If
On Error GoTo 0
oWord.Application.Visible = True
oWord.Application.Activate
With oWord
..Documents.Open Filename:="E:\Documents\Angelika's Studio\Permanent
Make-Up\Post Instructions.doc", ReadOnly:=False
..Application.Run MacroName:="Normal.NewMacros.Print10"
oWord.Quit
End With
Set oWord = Nothing
End Sub


Thanks in advance,
Rocky McKinley




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import into Access from Excel, passing a variable for the field... [email protected] Excel Worksheet Functions 1 April 12th 07 09:44 AM
Passing Data From Excel to Word Mark T[_2_] Excel Programming 1 November 19th 04 11:04 PM
Passing information from VBA variable to Excel range Doug R Excel Programming 1 April 30th 04 02:52 PM
Auto Open and Passing variable value(s) to MS Word Sony[_2_] Excel Programming 1 September 29th 03 05:00 AM
passing variables from excel to word Mike NG Excel Programming 8 July 22nd 03 12:08 PM


All times are GMT +1. The time now is 09:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"