ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Why does this not work (https://www.excelbanter.com/excel-programming/378461-why-does-not-work.html)

doj

Why does this not work
 
I want the file containing the macro to close the "Label Supplier
Stock.xls" file on closing.

Why does it give me "error 9 - subscript out of range"???

DG

Option Explicit
Option Base 1

Const StkFile = "G:\Planning\Packaging\packaging2\Label Stocks\Label
Supplier Stock.xls"
Const StkFile_window = "Label Supplier Stock.xls"
'


Private Sub Workbook_BeforeClose(Cancel As Boolean)

Windows(StkFile_window).Close savechanges:=False

End Sub

Private Sub Workbook_Open()

Dim this_workbook_name As String

this_workbook_name = ThisWorkbook.Name
Workbooks.Open Filename:=StkFile, UpdateLinks:=False
Windows(this_workbook_name).Activate


End Sub


Bob Phillips

Why does this not work
 
Maybe try Workbooks instead of Windows

--
HTH

Bob

(change the xxxx to gmail if mailing direct)
"doj" wrote in message
oups.com...
I want the file containing the macro to close the "Label Supplier
Stock.xls" file on closing.

Why does it give me "error 9 - subscript out of range"???

DG

Option Explicit
Option Base 1

Const StkFile = "G:\Planning\Packaging\packaging2\Label Stocks\Label
Supplier Stock.xls"
Const StkFile_window = "Label Supplier Stock.xls"
'


Private Sub Workbook_BeforeClose(Cancel As Boolean)

Windows(StkFile_window).Close savechanges:=False

End Sub

Private Sub Workbook_Open()

Dim this_workbook_name As String

this_workbook_name = ThisWorkbook.Name
Workbooks.Open Filename:=StkFile, UpdateLinks:=False
Windows(this_workbook_name).Activate


End Sub





All times are GMT +1. The time now is 01:21 AM.

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