ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Error only without references (https://www.excelbanter.com/excel-programming/313507-error-only-without-references.html)

JJZ[_3_]

Error only without references
 
Hello,

I'm using VB6 and I created a project (EXE-file) to test this code.

With the project - references - excel library turned on, this code
runs just fine, but without it on, I get Error 1004.




Dim xlapp As Object
Private Sub Form_Load()

If xlapp Is Nothing Then
Set xlapp = CreateObject("Excel.Application")
Else
Set xlapp = GetObject(, "Excel.Application")
End If

xlapp.Visible = True
excelfile = "c:\filename.xls"

xlapp.workbooks.Open FileName:=excelfile, ReadOnly:=True
If xlapp.ActiveWorkbook.ReadOnly = True Then
xlapp.ActiveWorkbook.ChangeFileAccess xlReadWrite
Else
xlapp.ActiveWorkbook.ChangeFileAccess xlReadOnly
End If


End Sub


does anyone know how to tackle this problem?

Kind regards,

JJ

keepITcool

Error only without references
 
These lines use constants found in the object library.
xlapp.ActiveWorkbook.ChangeFileAccess xlReadWrite
Else
xlapp.ActiveWorkbook.ChangeFileAccess xlReadOnly


in object browser you can find their actual values,
or use the Immediate pane:
?xlReadWrite
2
?xlReadOnly
3

use the values iso the constants :)



keepITcool

< email : keepitcool chello nl (with @ and .)
< homepage: http://members.chello.nl/keepitcool


(JJZ) wrote:

Hello,

I'm using VB6 and I created a project (EXE-file) to test this code.

With the project - references - excel library turned on, this code
runs just fine, but without it on, I get Error 1004.




Dim xlapp As Object
Private Sub Form_Load()

If xlapp Is Nothing Then
Set xlapp = CreateObject("Excel.Application")
Else
Set xlapp = GetObject(, "Excel.Application")
End If

xlapp.Visible = True
excelfile = "c:\filename.xls"

xlapp.workbooks.Open FileName:=excelfile, ReadOnly:=True
If xlapp.ActiveWorkbook.ReadOnly = True Then
xlapp.ActiveWorkbook.ChangeFileAccess xlReadWrite
Else
xlapp.ActiveWorkbook.ChangeFileAccess xlReadOnly
End If


End Sub


does anyone know how to tackle this problem?

Kind regards,

JJ




All times are GMT +1. The time now is 12:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com