Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Open a WorkBook - from Word
Message
De
05/07/2001 16:41:45
 
 
À
Tous
Information générale
Forum:
Visual Basic
Catégorie:
Codage, syntaxe et commandes
Titre:
Open a WorkBook - from Word
Divers
Thread ID:
00527189
Message ID:
00527189
Vues:
57
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform