Link to home
Start Free TrialLog in
Avatar of vmandem
vmandem

asked on

How to resolve the Excel error in my user's machine

I wrote a programme and I get this error at the following code

ERROR: Exception from HRESULT: 0X800A03EC

I get the above error only on the user machine but not on my machine when I pass the data value to the excel object like this:


Dim objX1 As Excel.Application
        Dim objXbook1 As Excel.Workbook
        Dim objXwith1 As Excel.Worksheet
 strdates = DateAdd(DateInterval.Day, -1, DATES)
                objXwith1.Cells._Default(i + 2, 31) = strdates.ToString("yyyy/MM/dd")

My excel template date column is of custom type and in the format
"yyyy/MM/dd".  Why I get the above error when I pass the date as string to the excel and IT HAPPENS ONLY ON ONE OF THE USERS MACHINE BUT WORKS FINE ON MY WORKSTATION.
ANY CLUE.
Thanks
VM
Avatar of mjwills
mjwills

Dim objX1 As Excel.Application
Dim objXbook1 As Excel.Workbook
Dim objXwith1 As Excel.Worksheet
strdates = DateAdd(DateInterval.Day, -1, DATES)
objXwith1.Cells._Default(i + 2, 31) = strdates.ToString("yyyy/MM/dd")

a) Show us your declaration of DATES, i and strdates.
b) Show us your assignment of DATES and i.
c) Does the code work if you change strdates.ToString("yyyy/MM/dd") to CDate(strdates)?
Avatar of vmandem

ASKER

I declared them as follows:

Dim strdates as date
dim i as integer

'I'm getting number of rows into an integer
  NumRows = UBound(varRolledUp, 2)

'My loop starts here
for i = o to numrows
DATES = varRolledUp(30, i)
 strdates = DateAdd(DateInterval.Day, -1, DATESTART)
'THE ERROR POPS UP ON USER MACHINE IN THE BELOW CODE
objXwith1.Cells._Default(i + 2, 6) = strdtstart.ToString("yyyy/MM/dd")
next

I HAVE NOT TRIED YOUR C OPTION. I CAN TRY AND LET YOU KNOW. DO YOU SUGGEST CHANGING THE FORMAT OF THE DATE COLUMN IN THE TEMPLATE TO SOMETHING ELSE INSTEAD OF CUSTOM TYPE "(yyyy/MM/dd)"

Thanks
vm
Avatar of vmandem

ASKER

Sorry I mentioned strdtstart at
objXwith1.Cells._Default(i + 2, 6) = strdtstart.ToString("yyyy/MM/dd")  

but it is strdates.ToString
Avatar of vmandem

ASKER

Any thoughts mjwills
a) The code has changed substantially between posting. Can you post the current code? Don't retype it - cut and paste it. I am particularly concerned by the changes of variable names (DATES -> DATESTART, strdates -> strdtstart etc).

b) Show us your declaration of DATES, DATESTART, NumRows and strdtstart . If you change any variable names or add any new variables, show me their declarations too.

c) Show us your assignment of DATESTART and strdtstart. If you change any variable names or add any new variables, show me their assignments too.

d) Does the code work if you change variablename.ToString("yyyy/MM/dd") to CDate(variablename)?

e) Also, can you confirm whether you have the lines:

Option Explicit On
Option Strict On

at the top of your file? You MUST have at least the first one.

f)  HAVE NOT TRIED YOUR C OPTION. I CAN TRY AND LET YOU KNOW. DO YOU SUGGEST CHANGING THE FORMAT OF THE DATE COLUMN IN THE TEMPLATE TO SOMETHING ELSE INSTEAD OF CUSTOM TYPE "(yyyy/MM/dd)"

See my c) suggestion, and try it out. Don't fiddle with other stuff - just make the requested change. The formatting of the date column in the Excel spreadsheet is irrelevant (trust me on this).
ASKER CERTIFIED SOLUTION
Avatar of mjwills
mjwills

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of vmandem

ASKER

mjwills

First of all the d) suggestion did not work on her workstaion and it gives the same error. Here is the current code I have it right now.

 Dim objX1 As Excel.Application
 Dim objXbook1 As Excel.Workbook
 Dim objXwith1 As Excel.Worksheet
Dim DATESTART As Date
objX1 = New Excel.Application

 objX1.Workbooks.Add(Application.StartupPath & "\Test.xlt")
            objXbook1 = objX1.Workbooks(objX1.Workbooks.Count)
            objX1.Visible = False
            objX1.ScreenUpdating = False
              ' Format and populate sheet
            objXwith1 = objXbook1.Worksheets(1)
DATESTART = varRolledUp(5, i)
 objXwith1.Cells._Default(i + 2, 6) = DateAdd(DateInterval.Day, -1, DATESTART)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

I CHANGED THE ABOVE LINE WITH YOUR OPTIONS LIKE CHANGING TO CDATE BUT THAT DID NOT WORKDED.
I HAVE NOT MADE ANY CHANGES TO THE TEMPLATE THOUGH AS YOU SUGGESTED AND IT REMAINS IN THE FORMAT AS CUSTOM(yyyy/mm/dd)
Avatar of vmandem

ASKER

mjwills no response from you on this, any thoughts about this.
You haven't answered *all* my questions (a - f). When you do, I'll respond.
Avatar of vmandem

ASKER

o.k. I will do that