ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA open xls as Read-Only? (https://www.excelbanter.com/excel-programming/355586-vba-open-xls-read-only.html)

hommer

VBA open xls as Read-Only?
 
I open a xls for inserting values from vba. However, I could not get over the
worksheet been openned as Read-Only part. Your help is appriciated!

Of cause, I did not come up with the original sample code. By the way, all
the samples I found are for opening a new xls then insert data into it. I
need to open an existing xls.
Here is my code: (m_objExcel is declared as Private m_objExcel As New cExcel)
Private Sub Command1_Click()
m_objExcel.OpenWorkbook "V:\my.xls", False
m_objExcel.StartExcel True
'after this line, I can see the xls, and its title said read-only
'next sub will insert the value, however, I would not be able to save it.
m_objExcel.InsertValue "L2", "20"
End Sub

Here are from class module:
Public Function OpenWorkbook(strFileName As String, fReadOnly As Boolean, _
Optional varPassword As Variant) As Excel.Worksheet
' Comments : Opens the named file and associates it with the class
' Parameters: strFileName - full path and name of the file to open
' fReadOnly - True to open readonly
If Not IsMissing(varPassword) Then
...
Else
Set m_objWorkbook = m_objExcel.Workbooks.Open(strFileName, , fReadOnly)
End If
End Function

Public Sub StartExcel(fVisible As Boolean)
' Comments : Starts an instance of Excel
' Parameters: fVisible - True to make Excel visible
....
m_objExcel.Visible = fVisible
....
End Sub







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

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