xlapp.workbooks.open(filename)

antonio.manoj.derose

Registered User.
Local time
Tomorrow, 04:34
Joined
Jul 4, 2013
Messages
62
Hi All,

The code is breaking when it is trying to open the code, above mentioned in the title.

x64 ms office suite, the same code works for the x32.

Note : code had been tweaked well and truly, with the change that required, declare ptrsafe for the x64.

Please shoot in all your comments

Thanks,

Antonio
 
Please help us and post the code and the error message if any...
 
Code:
 Option Compare Database
Option Explicit
 Public Sub XlfileImportTestNew()
 Dim rs As New ADODB.Recordset
Dim conn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim filename As String
Dim rsIn As DAO.Recordset
Dim db As Database
 Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlWrksht As Excel.Worksheet
Dim xlRange As Excel.Range
'Dim colIdx As Integer
'Dim sFile As Variant
'Dim strPath As String
    On Error GoTo XlfileImportTest_Error
 'MsgBox "Please choose file to upload relevant Claim form", vbOKOnly, "Choose file to import relevant claim form" removed on the 13th September
MsgBox "Please upload Commission Claim Form", vbOKOnly, "Commission Claim Form"
 filename = importFileName(".xlsm")
 If Len(filename) = 0 Then
Exit Sub
End If
 'Permit only excel files
If filename <> "" And Mid(filename, InStrRev(filename, ".") + 0, 5) <> ".xlsm" Then
    'importCSV = False
    MsgBox "Invalid filetype, only .xlsm files permitted", vbCritical, "Invalid File Type"
    Exit Sub
End If
 
If filename <> "" Then 'And Mid(filename, InStrRev(filename, "\") + 1, 6) = "Mobile" Then
    
    DoCmd.SetWarnings False
    
    With conn
    '.Provider = "Microsoft.Jet.OLEDB.4.0"
    .Provider = "Microsoft.ACE.OLEDB.12.0"
    .ConnectionString = "Data Source='" & filename & "'; " & "Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"
    .Open
    End With
    
    Set cmd.ActiveConnection = conn
    cmd.CommandType = adCmdText
    
    Select Case MsgBox("You are trying to import new claims data, This will delete the claims history.", vbYesNo Or vbExclamation Or vbDefaultButton1, "Do you agree?")
        
            Case vbYes
                        DoCmd.RunSQL "delete * from tblConsolidatedClaimform", False
                        'Call PctMeter(25, 100)
            Case vbNo
                        MsgBox ("Payments for Services not imported, exiting")
                        On Error GoTo 0
                        Exit Sub
    End Select
    
    
     cmd.CommandText = "SELECT * FROM [Claim Form$]"
    rs.CursorLocation = adUseClient
    rs.CursorType = adOpenStatic
    rs.LockType = adLockReadOnly
    rs.Open cmd
        
    Set db = CurrentDb()
    Set rsIn = db.OpenRecordset("select * from tblConsolidatedClaimform")
    
    Set xlApp = CreateObject("Excel.Application")
    [COLOR=yellow][COLOR=red]Set xlBook = xlApp.Workbooks.Open(filename)[/COLOR]
[/COLOR]   Set xlWrksht = xlBook.Sheets("Claim Form")
    Set xlRange = xlWrksht.Range("B23:J23")
   
    Dim rr As Integer
    rr = 2
    
    Dim coll As Integer
    coll = 23
    
    With xlWrksht
    While .Cells(coll, rr) <> ""
        rsIn.AddNew
        For rr = 2 To xlRange.Columns.Count
         rsIn.Fields(rr + 5) = .Cells(coll, rr)
         'good debug point
         'Debug.Print .Cells(coll, rr)
         Next rr
         rsIn.Fields("Store_Code") = xlWrksht.Cells(5, "C")
         rsIn.Fields("Premise_State") = xlWrksht.Cells(7, "C")
         rsIn.Fields("Store_Name") = xlWrksht.Cells(9, "C")
         rsIn.Fields("Email_Address") = xlWrksht.Cells(11, "C")
         rsIn.Fields("Date_Emailed_to_Telstra") = xlWrksht.Cells(13, "C")
         rsIn.Fields("Total_value_claim") = xlWrksht.Cells(5, "H")
         rsIn.Fields("Original_Claim_Number") = xlWrksht.Cells(11, "I")
         rsIn.update
        coll = coll + 1
        rr = 2
    Wend
    End With
    
    
    Call Claims_File(filename)
    
    'MsgBox "Records are succesfully imported", vbOKOnly, "Claim Form Import" removed on the 13th September 2013
    MsgBox "Records are succesfully imported"
    
    xlBook.Close (0)
    xlApp.Quit
    rs.Close
    Set rs = Nothing
    
    rsIn.Close
    Set rsIn = Nothing
    
IncorrectFile:
    On Error GoTo 0
   Exit Sub
   
XlfileImportTest_Error:
    'Newly added on the 11th of September 2013, in order to handle the error with the message 1004
    'If Err.Number = 1004 Then
     '   MsgBox "Unable to continue due to incorrect filename, please try re-running the claims reconciliation process"
      '  Err.Clear
       ' Exit Sub
    'Else
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure XlfileImportTest of Module Import"
    'End If
End If
   
End Sub
 
Last edited:
Help yourself out a little more and post the error message. :)
 
Hmm, please explain...

Code:
filename = importFileName(".xlsm")

Where is it supposed to get the *importFileName*?
 
Hi Gina,

Explanation below, please note that this code is working well, in the 32 bit, and yet it was well working for the 64 bit, when the creator was MS office 2013, now I have changed to Ms office 2010 for the 64 BIT, and the code is breaking in the font that I have mentioned in red.

Code:
'import file name for opening up the dialog box
Public Function importFileName(extensions As String) As String
 Dim dlgOpen As FileDialog
    On Error GoTo importFileName_Error
 Set dlgOpen = Application.FileDialog(msoFileDialogOpen)
 With dlgOpen
    .AllowMultiSelect = False
    If extensions <> "" Then
        .Filters.Clear
        .Filters.Add extensions & " files", "*" & extensions, 1
        .Filters.Add "All files", "*.*", 1
    End If
    
End With
 If dlgOpen.Show Then
 importFileName = dlgOpen.SelectedItems(1)
 Else
    Exit Function
End If
 'Dim importFileName(14) As String
'Dim zz As String
 'If dlgOpen.Show Then
        'Dim z As Integer
        'For z = 1 To dlgOpen.SelectedItems.Count
            'importFileName(z) = dlgOpen.SelectedItems(z)
        'Next z
'End If
 'importFileName = importFileNam(z)
    On Error GoTo 0
   Exit Function
 importFileName_Error:
     MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure importFileName of Module FileRead Functions"
    Exit Function
 End Function
Thanks,

Antonio
 

Attachments

  • 1004.PNG
    1004.PNG
    8.9 KB · Views: 197
Last edited:
Hi All,

Please see the error image too attached, file name - 1004.PNG, let me know how to show this error as a screenshot, so that I need not have to put in as an attachment,

Thanks,

Antonio
 
Hmm, does that file actually exist? Going to say yes, so what References do you have checked?
 
Hi Gina,

Which files are you asking for, please see attached for the libraries checked in.

Thanks,

Antonio
 

Attachments

  • libraries.JPG
    libraries.JPG
    51.3 KB · Views: 195
Yep, that's the list I was asking for... First, make a back up, second make a back up then uncheck...

Microsoft Visual Basic for Applications Extensibility [vbe6.dll] 5.3

Compact and Repair and try again, did the error go away?
 
Hi Gina,

Tried and the results are the same, do I have to uncheck repair, and then check again to see the errors.

I have done both the ways errors are the same.

Thanks,

Antonio
 
No, you don't but that one is usually the culprit as it hasn't been needed since Access 97. So, the next thing to try because seems to me you still have too many checked...

Uncheck the one that has *Multi-Dimensional* in the name. Remember make a back up first.
 
Hi Gina,

Will do, can you help me, take a backup, cause I reckon the backup is not equal to copy paste of the access file.

Thanks,

Antonio
 
Actually, a back IS a copy and paste of the file. :D That way anything goes wrong you can always go back to that copy.
 
Hi Gina,

I have removed the multidimension, and it had not given any joy for me, you know what, when I tried to load the xls file, it was successful in loading.

the issue it has is loading xlsm files, and just now I tried loading xlsx files, that would not load either.

It does seem like a setting thing for, I may be wrong, please shoot in all your comments, cause I have to get this thing running in loading xlsm files.

Thanks,

Antonio
 
Hi Gina,

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsm;
Extended Properties="Excel 12.0 Macro;HDR=YES";

resulted the same.

But Many many thanks Gina, on your continuous help, and am sure, getting close in resolving this.

Thanks,

Antonio
 

Users who are viewing this thread

Back
Top Bottom