Information générale
Catégorie:
Codage, syntaxe et commandes
Titre:
Open a WorkBook - from Word
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
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement