1

I have a vba script working on Windows (office 2007) that i use now on my Mac (Office 2011).

Everything works fine on Windows but i have a trouble with a button that doesn't run.

When running, i have a Method or data member not found error and the first lign is highlighted in yellow and the .Filters.Clear is highlighted in grey.

I don't know where is the problem..

Thanks for your help !

 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
manu
  • 49
  • 7

0 Answers0