[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


VB6 & MS Excel - Runtime error '1004'

Posted on 2016-08-18
Medium Priority
Last Modified: 2016-09-06
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.
Question by:nitin_s_shah
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 53

Accepted Solution

Ryan Chong earned 1000 total points (awarded by participants)
ID: 41760636
quick check if there's any Missing References in your Macro?
how your code looks like when you define the Excel objects?

instead of using:
Dim xlsApp As Excel.Application
Set xlsApp = New Excel.Application

Open in new window

try use:
Dim xlsApp As Object
Set xlsApp = CreateObject("Excel.Application")

Open in new window

instead, that could help.
LVL 76

Expert Comment

ID: 41760640
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.

Author Comment

ID: 41760658
Dear GrahamSkan,

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 41760662
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
        SelExcelHeaderNo = SelExcelHeaderNo + 1
    End If
    If SelExcelNo = 0 Then
       SelExcelNo = 1
       SelExcelNo = SelExcelNo ' + 1
    End If
    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
LVL 18

Assisted Solution

xtermie earned 1000 total points (awarded by participants)
ID: 41760795
Hi, do as Ryan propose first
Dim xlsApp As Object
Set xlsApp = CreateObject("Excel.Application")

and then check to see if you invoke the application with the workfile name:
myworkfile = "Financial-01_GG.xls"
Set myapp = Application.Workbooks(myworkfile)

Open in new window

Then do anything in Excel

Substitute APPLICATION with your EXCEL (i.e. XLSBK)
myworkfile with your variable for the workflie
and myapp with the combination of the two
LVL 18

Expert Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question