Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Subscript out of range error

Hello, I have been trying to fix this error but I have no clue why it's not
working. Any help would be greatly appreciated! I am getting "Subscript out
of range error" when I execute the coding given below, only when I HAVE AN
EXCEL INSTANCE OPEN. If I close all the excel instance and run the code
again, it works just fine. Here is the coding:

------------------------------
Dim xlsApp As Object
'I included this ExcelIsOpen function to see if an excel instance is already
open
'and if so, use that...but that doesn't seem to fix the issue

If ExcelIsOpen Then
Set xlsApp = GetObject(, "Excel.Application")
xlsApp.Visible = True
Else
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
End If

xlsApp.Workbooks.Open Filename:="C:\USERNAME\Import_UnmappedMoves.xls",
Password:="password", WriteResPassword:="password"

'am getting the error when the next line executes

Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

------------------------
Do you know where I am going wrong?

Thanks in advance for your help!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Subscript out of range error

Try activating the workbook first then activating the worksheet.

Workbooks("Import_unmappedmoves.xls").activate
worksheets("Moves").Activate
--
Regards,

OssieMac


"vcsphx" wrote:

Hello, I have been trying to fix this error but I have no clue why it's not
working. Any help would be greatly appreciated! I am getting "Subscript out
of range error" when I execute the coding given below, only when I HAVE AN
EXCEL INSTANCE OPEN. If I close all the excel instance and run the code
again, it works just fine. Here is the coding:

------------------------------
Dim xlsApp As Object
'I included this ExcelIsOpen function to see if an excel instance is already
open
'and if so, use that...but that doesn't seem to fix the issue

If ExcelIsOpen Then
Set xlsApp = GetObject(, "Excel.Application")
xlsApp.Visible = True
Else
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
End If

xlsApp.Workbooks.Open Filename:="C:\USERNAME\Import_UnmappedMoves.xls",
Password:="password", WriteResPassword:="password"

'am getting the error when the next line executes

Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

------------------------
Do you know where I am going wrong?

Thanks in advance for your help!

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Subscript out of range error

Hi,
The error is occuring because you have .xls in the line below
Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

Just remove the .xls
Workbooks("Import_unmappedmoves").worksheets("Move s").Activate
That shld work.

HTH,
--
Tausif Mohammed


"vcsphx" wrote:

Hello, I have been trying to fix this error but I have no clue why it's not
working. Any help would be greatly appreciated! I am getting "Subscript out
of range error" when I execute the coding given below, only when I HAVE AN
EXCEL INSTANCE OPEN. If I close all the excel instance and run the code
again, it works just fine. Here is the coding:

------------------------------
Dim xlsApp As Object
'I included this ExcelIsOpen function to see if an excel instance is already
open
'and if so, use that...but that doesn't seem to fix the issue

If ExcelIsOpen Then
Set xlsApp = GetObject(, "Excel.Application")
xlsApp.Visible = True
Else
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
End If

xlsApp.Workbooks.Open Filename:="C:\USERNAME\Import_UnmappedMoves.xls",
Password:="password", WriteResPassword:="password"

'am getting the error when the next line executes

Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

------------------------
Do you know where I am going wrong?

Thanks in advance for your help!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Subscript out of range error

Thanks for the response! But I have tried both of the suggested solutions
(activating the Workbook first before trying to activate the worksheet and
having the workbook name without .xls) with no luck. Do you know if there is
anything else that might be causing error?

Thanks a lot for your time and help! I really appreciate it!


"Tausif" wrote:

Hi,
The error is occuring because you have .xls in the line below
Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

Just remove the .xls
Workbooks("Import_unmappedmoves").worksheets("Move s").Activate
That shld work.

HTH,
--
Tausif Mohammed


"vcsphx" wrote:

Hello, I have been trying to fix this error but I have no clue why it's not
working. Any help would be greatly appreciated! I am getting "Subscript out
of range error" when I execute the coding given below, only when I HAVE AN
EXCEL INSTANCE OPEN. If I close all the excel instance and run the code
again, it works just fine. Here is the coding:

------------------------------
Dim xlsApp As Object
'I included this ExcelIsOpen function to see if an excel instance is already
open
'and if so, use that...but that doesn't seem to fix the issue

If ExcelIsOpen Then
Set xlsApp = GetObject(, "Excel.Application")
xlsApp.Visible = True
Else
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
End If

xlsApp.Workbooks.Open Filename:="C:\USERNAME\Import_UnmappedMoves.xls",
Password:="password", WriteResPassword:="password"

'am getting the error when the next line executes

Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

------------------------
Do you know where I am going wrong?

Thanks in advance for your help!

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Subscript out of range error

Hi Again,

I think this should def work.

The line on which you get error is
Workbooks("Import_unmappedmoves").worksheets("Move s").Activate
bcoz I think you are not referencing the xlsApp variable.
You need to prefix xlsApp.

Try
xlsApp.Workbooks("Import_unmappedmoves").worksheet s("Moves").Activate

OR
xlsApp.Workbooks("Import_unmappedmoves.xls").works heets("Moves").Activate

HTH,
--
Tausif Mohammed


"vcsphx" wrote:

Thanks for the response! But I have tried both of the suggested solutions
(activating the Workbook first before trying to activate the worksheet and
having the workbook name without .xls) with no luck. Do you know if there is
anything else that might be causing error?

Thanks a lot for your time and help! I really appreciate it!


"Tausif" wrote:

Hi,
The error is occuring because you have .xls in the line below
Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

Just remove the .xls
Workbooks("Import_unmappedmoves").worksheets("Move s").Activate
That shld work.

HTH,
--
Tausif Mohammed


"vcsphx" wrote:

Hello, I have been trying to fix this error but I have no clue why it's not
working. Any help would be greatly appreciated! I am getting "Subscript out
of range error" when I execute the coding given below, only when I HAVE AN
EXCEL INSTANCE OPEN. If I close all the excel instance and run the code
again, it works just fine. Here is the coding:

------------------------------
Dim xlsApp As Object
'I included this ExcelIsOpen function to see if an excel instance is already
open
'and if so, use that...but that doesn't seem to fix the issue

If ExcelIsOpen Then
Set xlsApp = GetObject(, "Excel.Application")
xlsApp.Visible = True
Else
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
End If

xlsApp.Workbooks.Open Filename:="C:\USERNAME\Import_UnmappedMoves.xls",
Password:="password", WriteResPassword:="password"

'am getting the error when the next line executes

Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

------------------------
Do you know where I am going wrong?

Thanks in advance for your help!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Subscript out of range error

WOW!!! Thank you very much!! That did it...

"Tausif" wrote:

Hi Again,

I think this should def work.

The line on which you get error is
Workbooks("Import_unmappedmoves").worksheets("Move s").Activate
bcoz I think you are not referencing the xlsApp variable.
You need to prefix xlsApp.

Try
xlsApp.Workbooks("Import_unmappedmoves").worksheet s("Moves").Activate

OR
xlsApp.Workbooks("Import_unmappedmoves.xls").works heets("Moves").Activate

HTH,
--
Tausif Mohammed


"vcsphx" wrote:

Thanks for the response! But I have tried both of the suggested solutions
(activating the Workbook first before trying to activate the worksheet and
having the workbook name without .xls) with no luck. Do you know if there is
anything else that might be causing error?

Thanks a lot for your time and help! I really appreciate it!


"Tausif" wrote:

Hi,
The error is occuring because you have .xls in the line below
Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

Just remove the .xls
Workbooks("Import_unmappedmoves").worksheets("Move s").Activate
That shld work.

HTH,
--
Tausif Mohammed


"vcsphx" wrote:

Hello, I have been trying to fix this error but I have no clue why it's not
working. Any help would be greatly appreciated! I am getting "Subscript out
of range error" when I execute the coding given below, only when I HAVE AN
EXCEL INSTANCE OPEN. If I close all the excel instance and run the code
again, it works just fine. Here is the coding:

------------------------------
Dim xlsApp As Object
'I included this ExcelIsOpen function to see if an excel instance is already
open
'and if so, use that...but that doesn't seem to fix the issue

If ExcelIsOpen Then
Set xlsApp = GetObject(, "Excel.Application")
xlsApp.Visible = True
Else
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
End If

xlsApp.Workbooks.Open Filename:="C:\USERNAME\Import_UnmappedMoves.xls",
Password:="password", WriteResPassword:="password"

'am getting the error when the next line executes

Workbooks("Import_unmappedmoves.xls").worksheets(" Moves").Activate

------------------------
Do you know where I am going wrong?

Thanks in advance for your help!

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
Runtime Error - Subscript out of range despite On Error statement DoctorG Excel Programming 3 July 28th 06 03:56 PM
Subscript out of range error - save copy error bg18461[_16_] Excel Programming 2 June 13th 06 04:53 PM
Subscript out of range error - save copy error bg18461[_15_] Excel Programming 1 June 13th 06 04:36 PM
Type Mismatch error & subscript out of range error Jeff Wright[_2_] Excel Programming 3 May 14th 05 07:14 PM
subscript out of range error Darren Excel Programming 3 November 24th 04 03:38 PM


All times are GMT +1. The time now is 04:41 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"