Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA open xls as read-only

I open an xls and insert value to it from VBA. However, the xls is opened as
read-only, even though the code asked for none-read-only access. Btw, all the
samples I found are for opening a new xls then insert data, and I need to
open an existing xls.

Your help is appreciated!

Here is my calling code block: (m_objExcel is declared as New cExcel)
Private Sub Command1_Click()
m_objExcel.StartExcel True
m_objExcel.OpenWorkbook "V:\my Report.xls", True
€˜I can see the xls after last line is run, but the title says read-only
€˜the next line will insert value, but later it wouldnt save.
m_objExcel.InsertValue "L2", "20"
m_objExcel.CloseExcel

End Sub
Below are sub/functions from sample code in class module.
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

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default VBA open xls as read-only

m_objExcel.OpenWorkbook "V:\my Report.xls", True

Sure looks to me that you're passing True as the Readonly argument to
Function OpenWorkbook.

--
Jim
"hommer" wrote in message
...
|I open an xls and insert value to it from VBA. However, the xls is opened
as
| read-only, even though the code asked for none-read-only access. Btw, all
the
| samples I found are for opening a new xls then insert data, and I need to
| open an existing xls.
|
| Your help is appreciated!
|
| Here is my calling code block: (m_objExcel is declared as New cExcel)
| Private Sub Command1_Click()
| m_objExcel.StartExcel True
| m_objExcel.OpenWorkbook "V:\my Report.xls", True
| 'I can see the xls after last line is run, but the title says read-only
| 'the next line will insert value, but later it wouldn't save.
| m_objExcel.InsertValue "L2", "20"
| m_objExcel.CloseExcel
|
| End Sub
| Below are sub/functions from sample code in class module.
| 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
|
| 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
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default VBA open xls as read-only

I am sorry, I pasted the code from my second try. First time, I did pass in
false, and it did not work.

"Jim Rech" wrote:

m_objExcel.OpenWorkbook "V:\my Report.xls", True


Sure looks to me that you're passing True as the Readonly argument to
Function OpenWorkbook.

--
Jim
"hommer" wrote in message
...
|I open an xls and insert value to it from VBA. However, the xls is opened
as
| read-only, even though the code asked for none-read-only access. Btw, all
the
| samples I found are for opening a new xls then insert data, and I need to
| open an existing xls.
|
| Your help is appreciated!
|
| Here is my calling code block: (m_objExcel is declared as New cExcel)
| Private Sub Command1_Click()
| m_objExcel.StartExcel True
| m_objExcel.OpenWorkbook "V:\my Report.xls", True
| 'I can see the xls after last line is run, but the title says read-only
| 'the next line will insert value, but later it wouldn't save.
| m_objExcel.InsertValue "L2", "20"
| m_objExcel.CloseExcel
|
| End Sub
| Below are sub/functions from sample code in class module.
| 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
|
| 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
|
|



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default VBA open xls as read-only

hommer,
As long as you are actually passing False in you code, the file system may
have set the file to Read Only, then it is not within the control of Excel.
For the file, right-click and check the Properties. Is the Read Only
Attribute set ?

NickHK

"hommer" wrote in message
...
I am sorry, I pasted the code from my second try. First time, I did pass

in
false, and it did not work.

"Jim Rech" wrote:

m_objExcel.OpenWorkbook "V:\my Report.xls", True


Sure looks to me that you're passing True as the Readonly argument to
Function OpenWorkbook.

--
Jim
"hommer" wrote in message
...
|I open an xls and insert value to it from VBA. However, the xls is

opened
as
| read-only, even though the code asked for none-read-only access. Btw,

all
the
| samples I found are for opening a new xls then insert data, and I need

to
| open an existing xls.
|
| Your help is appreciated!
|
| Here is my calling code block: (m_objExcel is declared as New cExcel)
| Private Sub Command1_Click()
| m_objExcel.StartExcel True
| m_objExcel.OpenWorkbook "V:\my Report.xls", True
| 'I can see the xls after last line is run, but the title says

read-only
| 'the next line will insert value, but later it wouldn't save.
| m_objExcel.InsertValue "L2", "20"
| m_objExcel.CloseExcel
|
| End Sub
| Below are sub/functions from sample code in class module.
| 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
|
| 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
|
|





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open in Read Only Barb W Excel Discussion (Misc queries) 6 October 21st 08 07:03 PM
VBA open xls as Read-Only? hommer Excel Programming 1 March 9th 06 08:10 PM
VBA open xls as Read-Only? hommer Excel Programming 0 March 9th 06 04:59 PM
open as read only Newbie80[_11_] Excel Programming 1 August 10th 05 02:28 PM
Open as read-only Dave Excel Worksheet Functions 0 July 26th 05 01:21 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"