+ Reply to Thread
Results 1 to 2 of 2

VBA open xls as Read-Only?

  1. #1
    hommer
    Guest

    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 wouldn’t save.
    m_objExcel.InsertValue "L2", "20"
    m_objExcel.CloseExcel

    End Sub
    Below are sub/functions from the 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. #2
    hommer
    Guest

    RE: VBA open xls as Read-Only?

    Admin,
    Please remove this and the other one that dosn't have a reply associated
    with it.
    Sorry I did not mean to double post. I got the server error message when I
    clicked post, so I tried couple more times, and they all made it.

    "hommer" wrote:

    > 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 the 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1