Passing a Word variable to Excel in Office 2010

Strider71

New Member
Joined
Jan 27, 2012
Messages
7
Hey guys, I'm trying to pass a variable from Word to Excel. Basically I have a Word document with a plain text content control in it. I'll have users populate this field. I know how to create a reference to that content contol in Word VBA that'll tell me what's in that content control
(eg.
Code:
MyWordVar = ActiveDocument.ContentControls(1).Range.Text
).
What I can't figure out is how to pass the value of "MyWordVar" to a variable in Excel.
Would anyone have any thoughts on how to do that?
It would be much appreciated!
Thanks.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Can you do something like, CELLS(row, column)=MyWordVar

That will paste the word variable into whatever cell you want in the excel spreadsheet.
 
Upvote 0
Can you do something like, CELLS(row, column)=MyWordVar

That will paste the word variable into whatever cell you want in the excel spreadsheet.

Thanks for replying,tybaltlives!

I've tried several combinations of this, but I just can't get it right though. I've even tried to have Excel run the word subroutine, but it doesn't pass the variable over to Excel. For the Word sub I have:
Code:
Public MyWordVar
Sub test()    
    
    MyWordVar = ActiveDocument.ContentControls(1).Range.Text
    
End Sub

And the Excel sub:
Code:
Public myExcelVar As String
Sub passtest()
    
    
    Dim wordApp As Object
    Set wordApp = CreateObject("Word.Application")
    wordApp.documents.Open Filename:="E:\Wordtest.docm"
    wordApp.Visible = True
    wordApp.Run "!module1.test"

    'I've tried things like these:
    myExcelVar = MyWordVar  'Or ...
    myExcelVar = ActiveDocument.ContentControls(1).Range.Text  'Or...
    Activesheet.Cells(1,1) = MyWordVar
    
End Sub

But it just doesn't pass it through to Excel. :(
 
Upvote 0

Forum statistics

Threads
1,203,073
Messages
6,053,381
Members
444,660
Latest member
Mingalsbe

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top