ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   error when using variable name for workbook (https://www.excelbanter.com/excel-programming/321714-error-when-using-variable-name-workbook.html)

Emma

error when using variable name for workbook
 
I am getting an error he

Sheets("Sheet1").Copy After:=Windows(sFile).Sheets(1)

which says that

"Object doesn't support this property or method"

Here is the code that I used:

Call GetContractFileName

Workbooks.Open
FileName:="G:\USER\Contracts\Data_Files\All_2004_C atalog.xls"
sFile = contractfilename
cntNo = ContractNo
Sheets("Sheet1").Copy After:=Windows(sFile).Sheets(1)
Windows(sFile).Activate
Sheets(cntNo).Select
_____________________________________
Public Function GetContractFileName()
ContractNo = InputBox("Enter the Contract Number: ", "Contract File")
contractfilename = ContractNo & ".xls"

End Function


nippetee

error when using variable name for workbook
 
have you wrote declaration for contractfilename variable in declarations
section?
that must be done to use variables between subs..

"Emma" kirjoitti:

I am getting an error he

Sheets("Sheet1").Copy After:=Windows(sFile).Sheets(1)

which says that

"Object doesn't support this property or method"

Here is the code that I used:

Call GetContractFileName

Workbooks.Open
FileName:="G:\USER\Contracts\Data_Files\All_2004_C atalog.xls"
sFile = contractfilename
cntNo = ContractNo
Sheets("Sheet1").Copy After:=Windows(sFile).Sheets(1)
Windows(sFile).Activate
Sheets(cntNo).Select
_____________________________________
Public Function GetContractFileName()
ContractNo = InputBox("Enter the Contract Number: ", "Contract File")
contractfilename = ContractNo & ".xls"

End Function


Emma

error when using variable name for workbook
 
Yes actually the error was in the syntax . I had to replace Window with
workbooks.

"nippetee" wrote:

have you wrote declaration for contractfilename variable in declarations
section?
that must be done to use variables between subs..

"Emma" kirjoitti:

I am getting an error he

Sheets("Sheet1").Copy After:=Windows(sFile).Sheets(1)

which says that

"Object doesn't support this property or method"

Here is the code that I used:

Call GetContractFileName

Workbooks.Open
FileName:="G:\USER\Contracts\Data_Files\All_2004_C atalog.xls"
sFile = contractfilename
cntNo = ContractNo
Sheets("Sheet1").Copy After:=Windows(sFile).Sheets(1)
Windows(sFile).Activate
Sheets(cntNo).Select
_____________________________________
Public Function GetContractFileName()
ContractNo = InputBox("Enter the Contract Number: ", "Contract File")
contractfilename = ContractNo & ".xls"

End Function



All times are GMT +1. The time now is 01:12 PM.

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