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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GetOpenFilename;PROBLEM WITH CLOSING THE FILE I OPENED

Status
Not open for further replies.

romij29

Technical User
Nov 23, 2004
49
GB
Hello To all,
How are ya?/
I have a slight problem with this code.

Sub mnuFileOpen_Click()
Dim FullFileName As String

FullFileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls", False)

Application.StatusBar = "Opening " & FullFileName

Workbooks.Open FullFileName

Sheets(1).Range("A:H").Copy

Workbooks("Trading Accounts.xls").Activate
Sheets("FMA Data").Select
Range("A1").Select
Selection.PasteSpecial xlValues

'Workbooks("Trading Accounts.xls").Sheets("FMA Data").Range("A1").PasteSpecial xlValues

Workbooks(FullFileName).Activate

Application.CutCopyMode = False

Application.StatusBar = "Closing " & FullFileName

ActiveWindow.Close


Application.StatusBar = False

End Sub

When I get to "Workbooks(FullFileName).Activate", i get the error
Runtime Error 9 - Subscript out of range.
I have checked help files but I have no clue what it is saying since I am new to Vba.

Thanks
 
Hi,

Try this...
Code:
Sub mnuFileOpen_Click()
    Dim FullFileName As String

    Dim wbThis As Workbook, wbOpen As Workbook

    Set wbThis = ActiveWorkbook

    FullFileName = Application.GetOpenFilename("Excel Files (*.xls),*.xls", False)
    
    Application.StatusBar = "Opening " & FullFileName
    
    Set wbOpen = Workbooks.Open(FullFileName)
    
    wbOpen.Sheets(1).Range("A:H").Copy
    
    wbThis.Sheets("FMA Data").Range("A1").PasteSpecial xlValues
    
    Application.StatusBar = "Closing " & FullFileName
    
    wbOpen.Close
    
    Application.StatusBar = False

End Sub

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Hello SkipVought,

I must say that you just made my day soo much simpler and I wanna thank ya for your assistance.Very well appreciated.
The code worked like a charm.

I also need to know something about multiselect.I tried setting it in the code to true to enable me pick two files at the same time and copy two different infos to two worksheets in the Activeworkbook(wbThis).
This doesn't give me the option to select these files(which re incidentally in different folders)at the same time.
Any thoughts on this?

Thanks a mill
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top