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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run-time error 5941 only in the Word templates

Status
Not open for further replies.

Lumpazi

Technical User
May 8, 2012
2
CH
Hello
I have been trying to get this Macro to work but I have had no luck.
It works fine, but when I put my word file with the macro in “My templates” it shows me an error:
Run-time error 5941
The request member of the collection does not exist.

The error occurs in this line:
For Each Zelle In ActiveDocument.Tables(1).Rows(cboAOrt.ListIndex + 2).Cells


Dim Zelle As Cell
Dim Bereich As Range

I = 0
If cboAOrt.ListIndex = -1 Then cboAOrt.ListIndex = 0
For Each Zelle In ActiveDocument.Tables(1).Rows(cboAOrt.ListIndex + 2).Cells
Set Bereich = ActiveDocument.Range(Start:=Zelle.Range.Start, End:=Zelle.Range.End - 1)
Select Case I
Case 0
Nr = 1
Zweigstelle = Bereich.Text
Case 1
Strasse = Bereich.Text
Case 2
Ort = Bereich.Text
Case 3
Telefon = Bereich.Text
Case 4
Telefax = Bereich.Text
Case 5
Mail = Bereich.Text
Case 6
Name = Bereich.Text
Case 7
Titel = Bereich.Text
End Select
I = I + 1
Next Zelle
ActiveDocument.Close




Has anybody any ideas why?

Thanks for any help
 
Have you tried to replace ActiveDocument with ThisDocument ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you for your reply.
Solved!
If someone has the same problem...

It seems that the macro could not start properly when I opened the file with the macro from "My templates". The 2nd docx file with the data could not be loaded.
So I opened the docx file with the data, whit a 2nd macro and it works.
Code:
Dim path As String 
    
    Application.ScreenUpdating = True 
    
    path = Options.DefaultFilePath(wdWorkgroupTemplatesPath) 
    path = "C:\..........................." 
    Documents.Open FileName:=path + "\data.docx", ReadOnly:=False
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top