我在Windows(Office 2007)上有一个vba脚本,我现在在Mac上使用它(Office 2011)。
在Windows上一切正常,但我遇到了一个无法运行的按钮。
运行时,我找不到方法或数据成员错误,第一个lign突出显示为黄色和.Filters.Clear 以灰色突出显示。
我不知道问题出在哪里..
感谢您的帮助!
Sub Button5_Click()
Application.ScreenUpdating = False 'à mettre en début de chaque macro !!!
If CommandButton5 = Click Then
ChDir ("Marcin2:Comptasoft:ListingClient")
'Declare a variable as a FileDialog object.
Dim fd As FileDialog
'Create a FileDialog object as a File Picker dialog box.
Set fd = Application.FileDialog(msoFileDialogFilePicker)
'Declare a variable to contain the path of each selected item. Even though the path is a String,
'the variable must be a Variant because For Each...Next routines only work with Variants and Objects.
Dim vrtSelectedItem As Variant
'Use a With...End With block to reference the FileDialog object.
With fd
'Change the contents of the Files of Type list.
'Empty the list by clearing the FileDialogFilters collection.
.Filters.Clear
'Add a filter that includes all files.
.Filters.Add "Fichiers texte", "*.txt"
'Use the Show method to display the File Picker dialog box and return the user's action.
'The user pressed the action button.
If .Show = -1 Then
'Step through each String in the FileDialogSelectedItems collection.
For Each vrtSelectedItem In .SelectedItems
'nom du fichier (adresse)
temp = vrtSelectedItem
'ouverture du fichier a revoir sous une feuille excel
Workbooks.OpenText Filename:=temp, _
DataType:=xlDelimited, Tab:=True
Next vrtSelectedItem
'The user pressed Cancel.
End If
End With
'Set the object variable to Nothing.
Set fd = Nothing
'Copie le nouveau nom du client sur la facture Client (feuil1)
Range("A2:a5").Select
Selection.Copy
Windows("Facturation.xlsm").Activate
Range("B19:b22").Select
ActiveSheet.Paste
Range("c19:c22").ClearContents
'fermer le fichier txt
Workbooks(2).Close
Workbooks(1).Worksheets(1).Activate
End If
Application.ScreenUpdating = True 'à mettre à la fin de chaque macro !!!
End Sub