Log in

View Full Version : Tools - Reference - Sending to Someone



Crikriek
11-25-2016, 07:49 AM
Hi Everyone,

I'm writing a code to translate an excel sheet into a word doc. To do so I had to check a box the tools - reference which I think was Microsoft Word 14.0 Object Library.

This file will be sent to many other people. Will this property be "automatically" checked when people will open the file ? Will the macro work without any action from other users ?

Thanks !

Christophe

SamT
11-25-2016, 11:25 AM
If you "checked" the Reference while in the Document to be shared, then it should be. Tool References are part of the Document.

gmayor
11-25-2016, 10:09 PM
If you want to ensure maximum compatibility you should use late binding to the Word object (see below), then the reference is unnecessary and there won't be any issues if the users don't have Word 2010. Note that any Word specific commands (typically those that begin with wd) will require those commands replacing with their numeric equivalents. As you appear to have Word 2010, you can check the enumeration using VBA help.

If you need more information about how to do this then post your code.


Dim wdApp As Object
Dim wdDoc As Object
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err Then
Set wdApp = CreateObject("Word.Application")
End If
On Error GoTo 0

Crikriek
12-09-2016, 06:04 AM
Hello,

I tried your code but that's not working. When I try to run the macro I get the error code : "Compile error : Can't Find project or library". Do you know how I could fix it ?

Thanks !

Christophe

Crikriek
12-09-2016, 06:17 AM
Hello,

I tried your code but that's not working. When I try to run the macro I get the error code : "Compile error : Can't Find project or library". Do you know how I could fix it ? Here below the start of my code


Sub Automate_Word_from_Excel_1()
'variables declared as a specific object type ie. specific to the application which is being automated:

Dim applWord As Object
Dim docWord As Object

Dim paraWord As Word.Paragraph
Dim Wb As Workbook
Dim WSel As Selection
Dim xlapp As Object
Dim xlBook As Object
Dim oShape As Object
Dim oWdShape As InlineShape
Dim oRng As Variant
Dim LastRow As Long
Dim CountAcc As Long
Dim CountUse As Long
Dim a As Long
Dim b As Long
Dim c As Long
Dim d As Long

'Activate Word Object
On Error Resume Next
Set applWord = GetObject(, "Word.application")
If Err Then
Set applWord = CreateObject("Word.application")
End If

On Error GoTo 0
'Set the Application object variable to create a new instance of Word:
Set applWord = New Word.Application
'make the Word window visible:
applWord.Visible = True
'maximize Word window:
applWord.WindowState = wdWindowStateMaximize

'add a new word document:
Set docWord = applWord.Documents.Add
Set WSel = applWord.Selection

Thanks !

Christophe

gmayor
12-09-2016, 07:55 AM
Remove the lines
'Set the Application object variable to create a new instance of Word:
Set applWord = New Word.ApplicationThe Word application has already been created/accessed by the preceding lines.


'Activate Word Object
On Error Resume Next
Set applWord = GetObject(, "Word.application")
If Err Then
Set applWord = CreateObject("Word.application")
End If
With Late Binding you will need to use the numeric equivalents of Word specific commands such as wdWindowStateMaximize i.e in this instance 1

Crikriek
12-09-2016, 09:01 AM
Thank you ! Can't I just add "applWord." in front of my statements ? For instance applWord.wdWindowStateMaximize ?

Crikriek
12-09-2016, 09:42 AM
My code is currently pretty long, does the fact that I change from early to late binding will make that I have to input numeric commands instead of each wd...command ? If yes, is there a source of info where I could easily find the info to change my code ?

gmayor
12-09-2016, 09:39 PM
If you have Word 2010/2007 the wd command enumeration is in Word VBA help
For later versions you can search the web for (say) wdWindowStateMaximize
You will have to replace all such wd prefixed commands with the appropriate numbers

applWord.WindowState = 1