Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Word 2007 macro in Word 2010

Status
Not open for further replies.

shedlord2

Technical User
May 20, 2006
36
0
0
GB
Hi,

I raised this problem here before but had no responses. That thread is now closed but I still have the error, so thought I'd try posting it again, to see if anyone has any suggestions what we can do.

---

We have a CRM system, one function of which is to generate custom letters in Word using macros (they bring customer details from a SQL database into templates). Am just setting up PCs with Office 2010 for the first time and found the macros we have for Word 2007 don't work in Word 2010. The dialog box error is "this file could not be found". The portion of the macro brought up in the debugger is below, with the highlighted line it chokes at below.

I've read that Word 2010 is fully compatible with 2007, but wondered if that doesn't apply to Macros? Any clues what may be the cause? This is happening on Windows 7 PCs, but we have other Windows 7 PCs with Office 2007 and the problem doesn't occur with them, so it looks to be something different in how Word 2010 macros work.

Yes, I have raised it with the CRM supplier, but it may take some time for us to achieve support from them and I really need to resolve this within the next couple of days. Thanks in advance for any suggestions.

---

Private Sub NewForm()
Dim fn$
Dim pn$
Dim Title$

' On Error Goto Trap

Dim FileInfo As Object: Set FileInfo = WordBasic.DialogRecord.FileSummaryInfo(False)

WordBasic.CurValues.FileSummaryInfo FileInfo
' dot$ = FileInfo.Template
fn$ = FileInfo.FileName
pn$ = FileInfo.Directory
Title$ = FileInfo.Title

Dot$ = pn$ + "\" + fn$
WordBasic.DocClose 2

WordBasic.FileNew Template:=Dot$, NewTemplate:=0
If Title$ = "" Then Title$ = "New Merge Document"
WordBasic.FileSummaryInfo Title:=Title$
'Setting title sets DocumentDirty to true
WordBasic.SetDocumentDirty 0

bye:

End Sub

---

It highlights this line in the debug window...

WordBasic.FileNew Template:=Dot$, NewTemplate:=0

 
When the code fails, with the 'WordBasic.FileNew Template:=Dot$, NewTemplate:=0' line highlighted, have you checked the contents of the Dot$ variable (which isn't Dimmed, BTW) to see whether it's pointing to a valid folder & file?

Cheers
Paul Edstein
[MS MVP - Word]
 
Howdy,

if I read your code correctly, what you are doing is basically this:
1.) Open a template
2.) Execute the macro, which
- reads the template's Title property, storing it in a variable
- closes the template,
- opens a new document based on that template
- assigns the stored Title property to this new document.
- make the document non-dirty

That about correct?

If so: no need to!
If you create a new document based on a template, then this new document inherits the Title property of that template anyway, no need to set it!
Try without Word.Basic, use built-in properties and methods instead:
Code:
Private Sub NewForm()
Dim doc As Document, tpl As String

tpl = ActiveDocument.FullName 'this is full path and file name already concatenated
ActiveDocument.Close False

Set doc = Documents.Add(tpl)
    
If doc.BuiltInDocumentProperties("Title") = "" Then
    doc.BuiltInDocumentProperties("Title") = "New Merge Document"
    doc.Saved = True
End If


End Sub

Hope this helps.

Cheers,
MakeItSo


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 



hi,
generate custom letters in Word using macros (they bring customer details from a SQL database into templates).
Have you thought about using MailMerge?

Back around 1995, I used this technique to print personalized children's books. I loaded a single table with data necessary to print any of a dozen and a half different books.

No VBA required!!!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top