ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Windows.Activate (https://www.excelbanter.com/excel-programming/370675-windows-activate.html)

Steph

Windows.Activate
 
Hello all. The code below opens a file, copies the data on a specific sheet
from the opened file, then reactivates the original workbook and pastes the
data. It then goes back to the opened file and closes the file.

When a co-worker runs this code, we get a subscript out of range error on
the line :
Windows("Salary Non").Activate

When I run the code under a different logon, it works fine with no errors.
Is there something that may be logon specific that would cause this code to
fail for one user and not another? And is there a better way to accomplish
this that may eliminate the problem, meaning different syntax or different
commands?

Thanks so much!!

Sub Open_SN()
Set model = ActiveWorkbook
Workbooks.Open Filename:="\\server\folder1\folder2\folder3\Salary Non.xls"
Sheets("Format").Cells.Copy
model.Activate
SN.Select 'Sheet name set in properties window in VBE
Cells.Select
ActiveSheet.Paste
Windows("Salary Non").Activate
Application.CutCopyMode = False
ActiveWorkbook.Close
End Sub



Tom Ogilvy

Windows.Activate
 
always use

Windows("Salary Non.xls").Activate

this will work on all computers.

whether it works or not without the extension is an option in folder options
about displaying known file extensions.


--
Regards,
Tom Ogilvy


"Steph" wrote:

Hello all. The code below opens a file, copies the data on a specific sheet
from the opened file, then reactivates the original workbook and pastes the
data. It then goes back to the opened file and closes the file.

When a co-worker runs this code, we get a subscript out of range error on
the line :
Windows("Salary Non").Activate

When I run the code under a different logon, it works fine with no errors.
Is there something that may be logon specific that would cause this code to
fail for one user and not another? And is there a better way to accomplish
this that may eliminate the problem, meaning different syntax or different
commands?

Thanks so much!!

Sub Open_SN()
Set model = ActiveWorkbook
Workbooks.Open Filename:="\\server\folder1\folder2\folder3\Salary Non.xls"
Sheets("Format").Cells.Copy
model.Activate
SN.Select 'Sheet name set in properties window in VBE
Cells.Select
ActiveSheet.Paste
Windows("Salary Non").Activate
Application.CutCopyMode = False
ActiveWorkbook.Close
End Sub




[email protected]

Windows.Activate
 
Try puting xls on the end:

Windows("Salary Non.xls").Activate

James

Steph wrote:

Hello all. The code below opens a file, copies the data on a specific sheet
from the opened file, then reactivates the original workbook and pastes the
data. It then goes back to the opened file and closes the file.

When a co-worker runs this code, we get a subscript out of range error on
the line :
Windows("Salary Non").Activate

When I run the code under a different logon, it works fine with no errors.
Is there something that may be logon specific that would cause this code to
fail for one user and not another? And is there a better way to accomplish
this that may eliminate the problem, meaning different syntax or different
commands?

Thanks so much!!

Sub Open_SN()
Set model = ActiveWorkbook
Workbooks.Open Filename:="\\server\folder1\folder2\folder3\Salary Non.xls"
Sheets("Format").Cells.Copy
model.Activate
SN.Select 'Sheet name set in properties window in VBE
Cells.Select
ActiveSheet.Paste
Windows("Salary Non").Activate
Application.CutCopyMode = False
ActiveWorkbook.Close
End Sub



Steph

Windows.Activate
 
Thanks guys!!

"Tom Ogilvy" wrote in message
...
always use

Windows("Salary Non.xls").Activate

this will work on all computers.

whether it works or not without the extension is an option in folder
options
about displaying known file extensions.


--
Regards,
Tom Ogilvy


"Steph" wrote:

Hello all. The code below opens a file, copies the data on a specific
sheet
from the opened file, then reactivates the original workbook and pastes
the
data. It then goes back to the opened file and closes the file.

When a co-worker runs this code, we get a subscript out of range error on
the line :
Windows("Salary Non").Activate

When I run the code under a different logon, it works fine with no
errors.
Is there something that may be logon specific that would cause this code
to
fail for one user and not another? And is there a better way to
accomplish
this that may eliminate the problem, meaning different syntax or
different
commands?

Thanks so much!!

Sub Open_SN()
Set model = ActiveWorkbook
Workbooks.Open Filename:="\\server\folder1\folder2\folder3\Salary
Non.xls"
Sheets("Format").Cells.Copy
model.Activate
SN.Select 'Sheet name set in properties window in VBE
Cells.Select
ActiveSheet.Paste
Windows("Salary Non").Activate
Application.CutCopyMode = False
ActiveWorkbook.Close
End Sub







All times are GMT +1. The time now is 10:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com