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:
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
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