Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Reliability issue with some code

Hi, I am having some reliability issues with this code. Sometimes it
works other times it will produce a "runtime error 9" highlighting this
line of code:

Set wbTarget = Workbooks(NameOfFile)

My VBA skills are a little on the basic side at best and would
appreciate any advice on to eradicate this error once and for all.

Regards,
Dean

Sub Macro1()
'Macro purpose: Use the application.run method to execute
'a macro without arguments from another workbook

Dim PathToFile As String, _
NameOfFile As String, _
wbTarget As Workbook, _
CloseIt As Boolean

ActiveSheet.Unprotect Password:="XXXXXX"

Application.ScreenUpdating = False
MsgBox "This will take around 30 Minutes to Process"


'Set file name and location.
NameOfFile = "data.xls"
PathToFile = "C:\winnt40\profiles\backoffice\desktop\label update"

'Attempt to set the target workbook to a variable. If an error is
'generated, then the workbook is not open, so open it
On Error Resume Next
Set wbTarget = Workbooks(NameOfFile)

If Err.Number < 0 Then
'Open the workbook
Err.Clear
Set wbTarget = Workbooks.Open(PathToFile & "\" & NameOfFile)
CloseIt = True
End If

'Check and make sure workbook was opened
If Err.Number = 1004 Then
MsgBox "Sorry, but the file you specified does not exist!" _
& vbNewLine & PathToFile & "\" & NameOfFile
Exit Sub
End If
On Error GoTo 0

'Run the macro!
Application.Run Macro:="process_update"


End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kuder-Richardson #21 Formula for estimate test reliability [email protected] Excel Discussion (Misc queries) 5 April 3rd 23 06:52 PM
can excel calculate inter rater reliability? Brian Boru Excel Discussion (Misc queries) 1 March 9th 10 01:05 PM
Inter-rater reliability question inter-rater Excel Worksheet Functions 1 September 28th 08 12:23 PM
Reliability and Confidence and Excel Gerigto Excel Discussion (Misc queries) 5 September 5th 07 03:04 AM
reliability of macro results KHashmi316[_20_] Excel Programming 2 June 21st 05 11:04 PM


All times are GMT +1. The time now is 11:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"