code not executing in 1 particular remote desktop

excelguru123

New Member
Joined
Jun 23, 2021
Messages
6
Office Version
  1. 2013
Platform
  1. Windows
Hi all, I am running this code that has to work through multiple remote desktops. The issue is that it works from my own desktop and all of the other remote desktops except for one where it gives a run-time error 9: subscript out of range.

Prior to that, my code is calling a drive, opening a spreadsheet through the pathway:

VBA Code:
File = Cells(7, 4)
Path = Cells(7, 5)

ChDrive Left(Path, 1)
ChDir Path

Set wbMyWorkbook = Workbooks.Open(FileName:=File, UpdateLinks:=False, ReadOnly:=True)
wbMyWorkbook.Activate
[B]Set wsMyWorksheet = wbMyWorkbook.Worksheets("Sheet1")[/B]

I know Path works fine because it opens "wbMyWorkbook" but then it gives an error on the last line bolded. I added "wbMyWorkbook.Activate" incase it wasn't the active workbook but it still doesn't work. Only 1 of my remote desktops is running into this error. Any ideas would be much appreciated. Thanks.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Set wsMyWorksheet = wbMyWorkbook.Worksheets("Sheet1")
Have you already checked that the sheet with the name "Sheet1" exists in that book?

Try:

VBA Code:
Sub open_book()
  Dim wbMyWorkbook As Workbook
  Dim wsMyWorksheet As Worksheet
  Dim sFile As String, sPath As String, sName As String
    
  sFile = Cells(7, 4)
  sPath = Cells(7, 5)
  sName = "Sheet1"
  
  ChDrive Left(sPath, 1)
  ChDir sPath
  
  Set wbMyWorkbook = Workbooks.Open(Filename:=sFile, UpdateLinks:=False, ReadOnly:=True)
  If Evaluate("ISREF('" & sName & "'!A1)") Then
    Set wsMyWorksheet = wbMyWorkbook.Worksheets(sName)
  Else
    MsgBox "Sheet1 does not exists"
  End If
End Sub
 
Last edited:
Upvote 0
Have you already checked that the sheet with the name "Sheet1" exists in that book?

Try:

VBA Code:
Sub open_book()
  Dim wbMyWorkbook As Workbook
  Dim wsMyWorksheet As Worksheet
  Dim sFile As String, sPath As String, sName As String
   
  sFile = Cells(7, 4)
  sPath = Cells(7, 5)
  sName = "Sheet1"
 
  ChDrive Left(sPath, 1)
  ChDir sPath
 
  Set wbMyWorkbook = Workbooks.Open(Filename:=sFile, UpdateLinks:=False, ReadOnly:=True)
  If Evaluate("ISREF('" & sName & "'!A1)") Then
    Set wsMyWorksheet = wbMyWorkbook.Worksheets(sName)
  Else
    MsgBox "Sheet1 does not exists"
  End If
End Sub
Okay I tried this code and gives the message "Sheet1 does not exist" as indicated in your code. My question then is, why is it not detecting Sheet1? It does exist and it works in all my other remote desktops and how can I fix it?

A temporary and inefficient thing that seems to work is repeating this part of the code twice like this:

VBA Code:
Set wbMyWorkbook = Workbooks.Open(FileName:=File, UpdateLinks:=False, ReadOnly:=True)
wbMyWorkbook.Activate

Set wbMyWorkbook = Workbooks.Open(FileName:=File, UpdateLinks:=False, ReadOnly:=True)
wbMyWorkbook.Activate
Set wsMyWorksheet = wbMyWorkbook.Worksheets("Sheet1")
 
Upvote 0
Try enabling the AccessibilityCplAdmin library on that desktop
 
Upvote 0

Forum statistics

Threads
1,223,710
Messages
6,174,019
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top