Named Arguments not allowed Error.

puppy26

New Member
Joined
Feb 23, 2012
Messages
42
Hi Experts,
I'm trying to write a code to import the excel file into access. Here is the code..

Private Sub Command8_Click()
Dim strPathFile As Variant
Dim strFilter As String
Dim ahtAddFilterItem() As String
Dim ahtCommonFileOpenSave() As String
Dim lngFlags As Long
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.XLS")
strPathFile = ahtCommonFileOpenSave(InitialDir:="C:\Users\PZ8P95\Desktop\Excel testing\", _
Filter:=strFilter, OpenFile:=False, Flags:=lngFlags, _
DialogTitle:="Select the EXCEL file:") ---------------> In this line, I'm getting Compile error as Named arguements not allowed

If strPathFile = "" Then
MsgBox "No file was selected.", vbOK, "No Selection"
Exit Sub
End If
DoCmd.TransferSpreadsheet acImport, (strFilter \ "Excel file.xls"), _
Sheet1, strPathFile, False
End Sub

Please let me know what's the solution Please.

Many thanks!

Puppy
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Puppy

Is ahtCommonFileOpenSave a sub you have created or copied?

Perhaps the one here API: Call the standard Windows File Open/Save dialog box ?

If it is then you can call it like this.
Code:
Private Sub Command8_Click()
Dim strPathFile As Variant
Dim strFilter
Dim lngFlags As Long

    strFilter = ahtAddFilterItem("Excel Files (*.xls)", "*.XLS")
    strPathFile = ahtCommonFileOpenSave(InitialDir:="C:\Users\PZ8P95\Desktop\Excel testing\", _
                                        Filter:=strFilter, OpenFile:=False, Flags:=lngFlags, _
                                        DialogTitle:="Select the EXCEL file:")

    If strPathFile = "" Then
        MsgBox "No file was selected.", vbOK, "No Selection"
        Exit Sub
    End If
    
    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
                              "Sheet1", strPathFile, False
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,723
Messages
6,174,113
Members
452,544
Latest member
aush

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top