Excel VBA Workbooks.Open(...) returns error

lottrup

New Member
Joined
Mar 9, 2009
Messages
16
Hi,

I have a problem with the Workbooks.Open(fileName) method.

The sub I am using works perfectly fine on my computer but returns a "Cannot open workbook" on my colleague's computer. The sub looks as follows:

Code:
Sub ImportOldFile()
Dim fileName As String
Dim wbk, wbk2 As Workbook
fileName = Application.GetOpenFilename("Comma Separated Values (*.xlsm),*.xlsm")
If fileName <> "False" Then
    Sheets("Pivot data").Select
    Columns("A:V").Select
    Selection.ClearContents
    Sheets("Cash flow").Select
    Range("B6").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    Sheets("Pivot data").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
 
    Set wbk = Workbooks.Open(fileName)
    wbk.Sheets("Cash flow").Range("B7:T11000").Copy
 
    Set wbk2 = ThisWorkbook
 
    wbk2.Activate
    wbk2.Sheets("Pivot data").Cells(GetLastRow("Pivot data", 1) + 1, 1).Select
 
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
 
    wbk.Close
End If
End Sub

The code fails at the line saying Set wbk = Workbooks.Open(fileName). Does it make sense that the code cannot run on all computers? The only difference (as I see it) is that I am a Windows 7 user, and he is a an XP user.

I really hope that somebody can help me :)
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
just wondering if youre colleague's puta is running xl old but you are running 2007+ . the file extensions are different!
 
Upvote 0
EDIT:

Can your colleague open the file if he does so via Windows Explorer and via Office button>Open?

Is the file an xlsm or a csv file by the way? Your GetOpenFIlename didn't make this very clear
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,885
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top