Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Open a WorkBook - from Word
Message
 
To
05/07/2001 16:41:45
General information
Forum:
Visual Basic
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00527189
Message ID:
00527260
Views:
25
>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

Use the Open statement to open a file and use the Add statement to add a new empty workbook.
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform