Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't access another workbook with GetOpenFilename w/o error

Status
Not open for further replies.

tearsmith

Technical User
Sep 7, 2003
34
US
All,

I have a line of code that reads like this....


Private Sub CommandButton2_Click()

Dim str As String
Dim objExcel As Excel.Application
Dim objBook As Excel.Workbook

str = Application.GetOpenFilename("excel files_
(*.xls),*.xls")

Set objExcel = New Excel.Application
Set objBook = objExcel.Workbooks.Open(str)

objBook.Sheets("Sheet1").Select
Range("AB2:AB762").Select
Selection.Copy
Workbooks("code.xls").Activate
Sheets("Sheet2").Select
Range("B4").Select
ActiveSheet.Paste
ActiveWindow.ActivateNext
Range("AF2:AF762").Select
Selection.Copy
ActiveWorkbook.Close
Range("D4").Select
ActiveSheet.Paste
Range("B1").Select
Sheets("Sheet1").Paste

End Sub

The problem is, when the file selection box opens and I find my workbook to open, the macro bugs up and tells me that the document I choose ("86783.xls") cannot be accessed. What am I missing here? I am trying to get the information from AB1:AB762 into the macro worksheet, etc.

Any help would be great. Thanks in advance.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top