ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro references (https://www.excelbanter.com/excel-programming/380984-re-macro-references.html)

Bob Phillips

Macro references
 
The problem probably stems from the fact that you have a later version of
Word/Outlook than the users.

Solution 1: do you have a copy of the same version, and can you build the
macros in that version?

Solution 2: have you heard of late binding. Late binding binds to the object
library at run time, not at compile time, so it will pick up whatever
library that they have. You have to code differently, for instance, instead
of

Dim olApp As Outlook.Application

Set olApp = New Outlook.Application

you would use

Dim olApp As Object

Set olApp = CreateObject("Outlook.Application")

it also means that you cannot use application constants, you have to hard
code them. I have written a small paper on a technique, written for Outlook
but the technique is generic, which you can read at
http://xldynamic.com/source/xld.EarlyLate.html

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dave Shaw" wrote in message
...
I'm tearing my hair out here. I have an Excel Template containing macros
which do things using word and outlook. I have therefore added the
relevant
references.

When a user creates a new file using the template and a macro is run the
message "can't find project of library" occurs. The references seem to be
there but the problem occurs on every line.

Can anyone tell me how to rectify this? it is not feasible to make
adjustments to individual's machines.

thanks in advance






Bob Phillips

Macro references
 
You could set preference to word, then look it up in the object browser.

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dave Shaw" wrote in message
...
Bob

Thanks for that.....

I am using the same version as the other users so that isn't the problem
however your method seems to work.

However I'm not brilliant with Visual basic and am struggling a bit. An
extract of my current problem is that I don't know how I should I should
code
certain parts - the wdFormLetters wdtoggle etc. as these result in the
error
message.

hope you can help!

An extract of my script is:

Dim wrdApp As Object
Dim wrdDoc As Object

Set wrdApp = CreateObject("Word.Application")



Dim i As Integer
Set wrdApp = CreateObject("Word.Application")
wrdApp.Visible = True
Set wrdDoc = wrdApp.Documents.Add(Template:=sourcedoc _
, newtemplate:=False, DocumentType:=0)
With wrdDoc
wrdDoc.MailMerge.MainDocumentType = wdFormLetters
wrdDoc.MailMerge.OpenDataSource Name:= _
SourceName _
, ConfirmConversions:=False, ReadOnly:=False,
LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="",
PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="",
Revert:=False, _
Format:=wdOpenFormatAuto, Connection:="DSN=Excel Files;DBQ=" &
ThisWorkbook.FullName & ";DriverId=790;MaxBufferSize=2048;PageTimeout= 5;",
SQLStatement:="SELECT * FROM `Database`", _
SQLStatement1:=""

wrdDoc.MailMerge.EditMainDocument



wrdDoc.MailMerge.ViewMailMergeFieldCodes = wdToggle
wrdDoc.CommandBars("Mail Merge").Visible = False

wrdDoc.Select

With wrdDoc.MailMerge
.Destination = wdSendToNewDocument

.SuppressBlankLines = True
With .DataSource
.FirstRecord = wdDefaultFirstRecord
.LastRecord = wdDefaultLastRecord
End With
.Execute Pause:=False
wrdDoc.MailMerge.Application.Documents(1).SaveAs Filename:=savename,
FileFormat:=wdFormatDocument
End With
wrdDoc.Close SaveChanges:=wdDoNotSaveChanges
wrdApp.Quit

"Bob Phillips" wrote:

The problem probably stems from the fact that you have a later version of
Word/Outlook than the users.

Solution 1: do you have a copy of the same version, and can you build the
macros in that version?

Solution 2: have you heard of late binding. Late binding binds to the
object
library at run time, not at compile time, so it will pick up whatever
library that they have. You have to code differently, for instance,
instead
of

Dim olApp As Outlook.Application

Set olApp = New Outlook.Application

you would use

Dim olApp As Object

Set olApp = CreateObject("Outlook.Application")

it also means that you cannot use application constants, you have to hard
code them. I have written a small paper on a technique, written for
Outlook
but the technique is generic, which you can read at
http://xldynamic.com/source/xld.EarlyLate.html

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dave Shaw" wrote in message
...
I'm tearing my hair out here. I have an Excel Template containing
macros
which do things using word and outlook. I have therefore added the
relevant
references.

When a user creates a new file using the template and a macro is run
the
message "can't find project of library" occurs. The references seem to
be
there but the problem occurs on every line.

Can anyone tell me how to rectify this? it is not feasible to make
adjustments to individual's machines.

thanks in advance










All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com