Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Open a WorkBook - from Word
Message
From
05/07/2001 16:41:45
 
 
To
All
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Title:
Open a WorkBook - from Word
Miscellaneous
Thread ID:
00527189
Message ID:
00527189
Views:
56
Hi All,

I'm trying to open an Excel workbook and import a .txt file. I get an error on the "WorkBooks.Open" command - 4th statement in the sub below. What am I doing wrong? TIA.

Regards,

Paige

Option Explicit

Sub ImportTextUsingOpenText()

'\ Use this approach to pre-set all of the text import values
'\ and validate file selection before performing import

Dim sFile
Application.ScreenUpdating = False
Application.DisplayAlerts = False
WorkBooks.Open
Worksheets.Add
Range("A1") = "Open Text Method"
Range("A2").Select

'\ get file name from user
sFile = Application.GetOpenFilename( _
FileFilter:="Text Files (*.txt), *.txt", FilterIndex:=1, _
Title:="Copy Text File To Worksheet")
If sFile <> False Then

'\ supply other OpenText parameters here
WorkBooks.OpenText FileName:=sFile '\import text to temporary worksheet
ActiveSheet.UsedRange.Select '\ select imported text in temporary workbook
Selection.Copy '\ copy to clipboard
ActiveWorkbook.Close '\ close temporary workbook
ActiveSheet.Paste '\ paste text into your workbook
End If
End Sub
Next
Reply
Map
View

Click here to load this message in the networking platform