Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works
Photo

VB help ! Run-Time Error 5941


  • Please log in to reply

#1
gladdie

gladdie

    New Member

  • Member
  • Pip
  • 6 posts
Hi,

Recently i have writen a VBA code that works in Win XP but when i run the same code in Win 98, a run-time error occurs. It displays the following..

Run-time error "5941":
The requested member of the collection does not exist.



Here are part of my code:

Sub repeatHeader()
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=36
Selection.MoveRight Unit:=wdCharacter, Count:=21, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Rows.HeadingFormat = True :tazz: <-------- THIS PART IS HIGHTLIGHTED WHEN I PRESS DEBUG BUTTON
End Sub



I have been trying to troubleshoot this for a long time can someone plzzz help me ??
Thx !!!
  • 0

Advertisements


#2
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
thats the thing with VBA

Umm ok here goes

I am guessing that you are using and adding references.
(Tools, references)

I am also guessing that since u were using xp, the referneces were all updated like say Microsoft Word 11.0 or 10.0,

but in win98 the references were old , its probably Microsoft 8.0 or 9.0

i am guessing (not sure) that if u go

tools, references (in VB Editor)

that you can still make the project work

theres an option to browse. If u know what the file is called (Microsoft Word 11.0 or 10.0) than u could add it in and add in the check beside the reference

Im not sure if it works

but plz try it out and let me know

Stu Design
  • 0

#3
gladdie

gladdie

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Thks for the quick reply ;)

Well i did enable those in the reference. When the code rus in XP, i added Microsoft Word 10.0 object library and Excel 9.0 object library. (I'm not sure y there isn't excel 10.0.. the latest is 9.0)
As for Win98 it was Microsoft Word 10.0 object library and Excel 10.0.

The Run-Time Error 5941 still occurs.... :tazz:
  • 0

#4
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
hey gladdie

not sure on the solvation of ur problem ;)

but i did find thi s
hope this helps u out

http://search.micros...w=en-us&qu=5941

w8 maybe theres a way

Selection.Rows.HeadingFormat = true


are u sure that there are rows??
and if u are using excel my bad :tazz:

and if u are did you , in code, select which rows or cells you want the formated??


stu design

Edited by stu_design, 10 May 2005 - 08:04 AM.

  • 0

#5
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
and i found this

put this

Selection.Rows.HeadingFormat = wdToggle

instaed of

Selection.Rows.HeadingFormat = true


this may or may not work

stu design

Edited by stu_design, 10 May 2005 - 08:07 AM.

  • 0

#6
gladdie

gladdie

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Hi,

thx for the effort i will try to follow the link and will get back to you if i ever solve the solution.

Btw do you mind if i ask you another qns ?

My code is to suppose to generate a monthly report. Using the VBA, supposely by clicking the CommandButton4 will auto generate the report.

i edited the code, now i edited my code and not only tat it cant runs in XP, the error 5941 occur at a different place. When i click the CommandButton4, the report is generating halfway but stop at the part "Selection.Rows.HeadingFormat = True". I stop the code and attempt to run it again. Now another runtime error 4605 occur.... :tazz: ;) ;)

I shall paste the whole code you can have a better understanding of it.
Not sure u can understand wad im saying as i am very bad at explaining so any question feel free to ask i will try my best to answer.

Code:

Dim AppWord As Word.Application
Dim AppExcel As Excel.Application

Private Sub CommandButton4_Click()
Dim tmpText As String
Dim Msg As String, thisMonth As String, thisMonthYr As String
Dim s As Integer, i As Integer, j As Integer

'Process into Arrays

Dim file As file
Dim fld As Folder
Dim fso As New FileSystemObject
Dim SummarySize As Integer, DetailSize As Integer
Dim inputFiles_s() As String, inputFiles_d() As String
Dim outputFiles_s() As String, outputFiles_d() As String
Const DEFAULT_FILE_PATH As String = "C:\Sin\MMMYYYY\Source"

SummarySize = 0
DetailSize = 0
thisMonth = "_" & Format(DateAdd("m", -1, Date), "mmm") & "_"

If fso.FolderExists(DEFAULT_FILE_PATH) Then
Set fld = fso.GetFolder(DEFAULT_FILE_PATH)
For Each file In fld.Files

If InStr(UCase(file.Name), "MMM") > 0 Then

If InStr(UCase(file.Name), "SUMMARY") > 0 Then
If InStr(file, "MMM") > 0 And InStr(file, ".txt") > 0 Then

SummarySize = SummarySize + 1
ReDim Preserve inputFiles_s(SummarySize)
ReDim Preserve outputFiles_s(SummarySize)
inputFiles_s(SummarySize) = file
'MsgBox (file.Name)

outputFiles_s(SummarySize) = Replace(outputFiles_s(SummarySize), ".txt", ".doc")
outputFiles_s(SummarySize) = Replace(outputFiles_s(SummarySize), "_MMM_", thisMonth)
'MsgBox (outputFiles_s(SummarySize))

End If
End If

If InStr(UCase(file.Name), "DETAIL") > 0 Then
If InStr(file, "_MMM_") > 0 And InStr(file, ".txt") > 0 Then

DetailSize = DetailSize + 1
ReDim Preserve inputFiles_d(DetailSize)
ReDim Preserve outputFiles_d(DetailSize)
inputFiles_d(DetailSize) = file
'MsgBox (file.Name)

outputFiles_d(DetailSize) = Replace(inputFiles_d(DetailSize), "_MMM_", thisMonth)
outputFiles_d(DetailSize) = Replace(outputFiles_d(DetailSize), ".txt", ".doc")
'MsgBox (outputFiles_d(DetailSize))

End If
End If
End If
Next file
End If


'End process into arrays

'This loop is for the summary Files
For i = 1 To SummarySize
On Error GoTo error
If Not IsEmpty(inputFiles_s(i)) Then
Documents.Open inputFiles_s(i)
With ActiveDocument
.PageSetup.Orientation = wdOrientLandscape
If .Sentences.Count = 1 Then
.Sentences(1).ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.InsertAfter " " & vbCr
.Range.InsertAfter "Period: " & vbCr
.Range.InsertAfter "Report Date: " & vbCr
.Range.InsertAfter "Device Name,Event Summary,Outages,Total Down Time (Days:Hours:Minutes),Reason" & vbCr
.Range.InsertAfter "N/A,N/A,N/A,N/A"
Set ToConvert = .Range(Start:=.Sentences(4).Start)
ToConvert.ConvertToTable Separator:=wdSeparateByCommas
Else
Set FirstThree = .Range(Start:=.Sentences(1).Start, End:=.Sentences(3).End)
FirstThree.ParagraphFormat.Alignment = wdAlignParagraphCenter
s = .Sentences.Count - 1
Set RemainingText = .Range(Start:=.Sentences(4).Start, End:=.Sentences(s).End)
RemainingText.ConvertToTable Separator:=wdSeparateByCommas
insertHeader
CenterCols
insertFooter
repeatHeader
End If
.SaveAs FileName:=inputFiles_s(i), FileFormat:=wdFormatDocument
.OnTime When:=Now, Name:="CloseDocument"
.Close
End With

End If
error:
Next i
'End of loop for summary files

'This second loop is for the Detailed Files
For j = 1 To DetailSize
If Not IsEmpty(inputFiles_d(j)) Then
Documents.Open inputFiles_d(j)
With ActiveDocument
.PageSetup.Orientation = wdOrientLandscape
If .Sentences.Count = 1 Then
.Sentences(1).ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.InsertAfter " " & vbCr
.Range.InsertAfter "Period: " & vbCr
.Range.InsertAfter "Report Date: " & vbCr
.Range.InsertAfter "Device Name,Event Details,Polls Missed,DownTime DD:HH:MM,Reason" & vbCr
.Range.InsertAfter "N/A,N/A,N/A,N/A"
Set ToConvert = .Range(Start:=.Sentences(4).Start)
ToConvert.ConvertToTable Separator:=wdSeparateByCommas
Else
Set FirstThree = .Range(Start:=.Sentences(1).Start, End:=.Sentences(3).End)
FirstThree.ParagraphFormat.Alignment = wdAlignParagraphCenter
Set RemainingText = .Range(Start:=.Sentences(4).Start)
RemainingText.ConvertToTable Separator:=wdSeparateByCommas
insertHeader
CenterCols
insertFooter
repeatHeader
End If
.SaveAs FileName:=outputFiles_d(j), FileFormat:=wdFormatDocument
.OnTime When:=Now, Name:="CloseDocument"
.Close
End With
End If
Next j
'End of loop for Detailed Files
End Sub

Private Sub CommandButton5_Click()
End
End Sub

Private Sub insertHeader()
Selection.MoveDown Unit:=wdLine, Count:=3, Extend:=wdExtend
Selection.Copy
Selection.Cut
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.Paste
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub
Sub repeatHeader()
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.MoveLeft Unit:=wdCharacter, Count:=36
Selection.MoveRight Unit:=wdCharacter, Count:=21, Extend:=wdExtend
Selection.MoveLeft Unit:=wdCharacter, Count:=3, Extend:=wdExtend
Selection.MoveUp Unit:=wdLine, Count:=2, Extend:=wdExtend
Selection.MoveRight Unit:=wdCharacter, Count:=2, Extend:=wdExtend
Selection.Rows.HeadingFormat = True <---- THIS PART IS HIGHTLIGHTED WHEN I PRESS DEBUG BUTTON (runtime error 5941)
End Sub

Sub insertFooter()
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.MoveDown Unit:=wdLine, Count:=4
NormalTemplate.AutoTextEntries("Page X of Y").Insert Where:=Selection. _
Range
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
ActiveWindow.ActivePane.VerticalPercentScrolled = 0
End Sub

Sub CenterCols()
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.SelectColumn <---- THIS PART IS HIGHTLIGHTED WHEN I PRESS DEBUG BUTTON (runtime error 4605)
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter
Selection.MoveUp Unit:=wdLine, Count:=1
End Sub
  • 0

#7
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
am working on it
  • 0

#8
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
whats this ???

code:

Dim file As file
Dim fld As Folder
Dim fso As New FileSystemObject

im using word 2003 and it says that since u named it, its not defined anywhere. Could thsi be problem?

Im guessing u are using vba code in Word 2003
These are the error definitions and why it happens it may apply to you
(4605 and 5941)

http://support.micro...kb;en-us;813983

one of the symptoms is ...

This problem may occur if you do not have a document open, or if the document that you are referencing is not open. Word can only change the properties of an open (or visible) document.


and this may be happening bc of this ...

Dim file As file
Dim fld As Folder
Dim fso As New FileSystemObject


Hope this helps... ;) :) ;) :tazz:


Stu design

Edited by stu_design, 12 May 2005 - 11:10 AM.

  • 0

#9
gladdie

gladdie

    New Member

  • Topic Starter
  • Member
  • Pip
  • 6 posts
Hi, ;)

The FileSystemObject, or FSO, is an often used component to access the web server's file system. For example, you can create files, read the contents of files, determine whether or not a folder or file exists, iterate through the contents of a folder or directory. It can be use for any other number of file system-related tasks. You have to go to reference and check the Microsoft Runtime scripting.

If fso.FolderExists(DEFAULT_FILE_PATH) Then
Set fld = fso.GetFolder(DEFAULT_FILE_PATH)
For Each file In fld.Files


Im using this to check if the folder exists and if it exists, the file in the folder will be process into the arrays.

Anyway i remove remove all lines that causes me to have runtime error and strangely it works ! Im not sure why this worked but it just did.. ;) Thanks for your help i appreciate alot !! :tazz:
  • 0

#10
stu_design

stu_design

    Member

  • Member
  • PipPipPip
  • 217 posts
no prob
:tazz:

Stu Design
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP