Avatar of Nitin Shah
Nitin Shah
Flag for India asked on

VB6 & MS Excel - Runtime error '1004'

I have VB 6 application which read excel file as input file and generate excel .csv file as output, This is working fine on windows-xp, windows 7. But when i run application in windows 8.1 it is giving error as

Run-time error '1004':
Method '~' of object '~' failed.

I am using MS Excel 2013.

what could be reason for this.

Thanks in advance.
Visual Basic ClassicMicrosoft Excel

Avatar of undefined
Last Comment
Anastasia D. Gavanas

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
GrahamSkan

We will need to see the code and to know where it fails,

If you are running from a compiled .exe, switch to running the source code in the VBA IDE to see the failure point.
Nitin Shah

ASKER
Dear GrahamSkan,

I am not able to install vb6 on windows 8.1 profession.

Thanks
Nitin Shah

ASKER
Dear Ryan Chong,

following is my code.

Option Explicit
'************************************************************
    Dim XLSBK                    As New Excel.Application
    Dim XLwsh                    As New Excel.Worksheet
'************************************************************
    Dim exRow As Long, exCol As Integer, SelRowPerFile As Integer, SelPerFileNo As Integer
    Dim InpRow As Long, InpCol As Integer, InpData As String, InpError As String, ErrSw   As Integer
'************************************************************
    Dim mvExcel As New Excel.Application
    Dim mvWSht As New Excel.Worksheet
    Dim fileName As String, SaveFileName As Double
'************************************************************


''command button to open excel file

Private Sub OpenExcelDataBase()
'**********************************************************************
 
    Dim fs
    Set fs = CreateObject("scripting.filesystemobject")
    SelExcelFileName = Trim(ctlSELEXECLFILENAME.Text)
    If Trim(Len(SelExcelFileName)) = 0 Then
       MsgBox "Select Excel file", vbCritical, Me.Caption
       Exit Sub
    End If
'**********************************************************************
    If Not fs.FileExists(SelExcelFileName) Then
        MsgBox "Warning - Not a valid Excel file name ", vbCritical
        Exit Sub
    End If
'**********************************************************************
    XLSBK.DefaultFilePath = SelExcelFileName
'**********************************************************************
    XLSBK.Workbooks.Open SelExcelFileName, , , , , , , , , True
    XLSBK.Visible = False
'**********************************************************************
    If Trim(Len(Trim(ctlEXCELNO.Text))) = 0 Then
       ctlEXCELNO.Text = "0"
    End If
'**********************************************************************
    If Trim(Len(Trim(ctlEXECLHEADER.Text))) = 0 Then
       ctlEXECLHEADER.Text = "0"
    End If
'**********************************************************************
    SelExcelNo = Trim(ctlEXCELNO.Text)
    SelExcelHeaderNo = Trim(ctlEXECLHEADER.Text)
    If SelExcelHeaderNo = 0 Then
       SelExcelHeaderNo = 1
    Else
        SelExcelHeaderNo = SelExcelHeaderNo + 1
    End If
    If SelExcelNo = 0 Then
       SelExcelNo = 1
    Else
       SelExcelNo = SelExcelNo ' + 1
    End If
    XLSBK.Sheets(SelExcelNo).Activate
    Set XLwsh = XLSBK.Sheets(SelExcelNo)
    Dim x As Integer
    x = XLSBK.Sheets.Count
    RowCount = XLSBK.Sheets(SelExcelNo).UsedRange.Rows.Count
    ctlRowCount = Format(RowCount, "0")
'**********************************************************************
   
End Sub
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
SOLUTION
Anastasia D. Gavanas

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Anastasia D. Gavanas

Good comments and suggestions made and author did not get back to provide feedback