Solved

VB6 & MS Excel - Runtime error '1004'

Posted on 2016-08-18
6
30 Views
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.
0
Comment
Question by:nitin_s_shah
6 Comments
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 250 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.
0
 
LVL 76

Expert Comment

by:GrahamSkan
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.
0
 

Author Comment

by:nitin_s_shah
ID: 41760658
Dear GrahamSkan,

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

Thanks
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:nitin_s_shah
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
    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
0
 
LVL 17

Assisted Solution

by:xtermie
xtermie earned 250 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:
SET APPLICATION=GETOBJECT(,"EXCEL.APPLICATION")
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
0
 
LVL 17

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now