简体   繁体   中英

Using VB Excel Importing data text with open window

Hi i very new to VB programming in Excel. I've been assigned a job to create a macro to merge two external txt file. That's a problem that the location of this two files might be located differently in client side.

Here is the code that i am using. Is there anyway i can import data text with open window? And After i set the active cell to the last row, i wish to import another data text again and adjust the column width. Appreciate a lot for any suggestion.

Sub GetFile()

Dim fNameAndPath As Variant, wb As Workbook
    fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")
        If fNameAndPath = False Then Exit Sub
        Set wb = Workbooks.Open(fNameAndPath)

        Range("A1").Select
        ActiveCell.End(xlDown).Select
        ActiveCell.Offset(1, 0).Select
'
'do stuff
'
End Sub

Yes. Change this code:

fNameAndPath = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLS), *.XLS", Title:="Select File To Be Opened")

to this code:

fNameAndPath = Application.GetOpenFilename(FileFilter:="Text Files (*.TXT), *.TXT", Title:="Select File To Be Opened")

Then instead of using Workbook.Open , use Workbook.OpenText .
To get the correct syntax, record macro and try opening the file in excel.
Then edit the macro code based on what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM