• Status: Solved
  • Priority: Medium
  • Security: Private
  • Views: 11
  • Last Modified:

Opening a workbook as read-only through VBA code

Hi, I am using the following code to open another workbook, and eventually do some copy/pasting into the workbook housing the VBA code. However, I need to able to open the workbook as a read only. Can I modify the following code to achieve that?
' Get source workbook...

    Dim filter As String
    Dim caption As String
    Dim sourceFilename As String
    Dim sourceWorkbook As Workbook
    Dim targetWorkbook As Workbook

    ' make weak assumption that active workbook is the target
    Set targetWorkbook = Application.ActiveWorkbook

    ' get the source workbook
    filter = "Excel Workbooks (*.xlsx; *.xlsm),*.xlsx;*.xslm"
    caption = "Please Select an input file with the RDT."

    sourceFilename = Application.GetOpenFilename(filter, , caption)

    Set sourceWorkbook = Application.Workbooks.Open(sourceFilename)

Open in new window

0
Dmitriy Kritskiy
Asked:
Dmitriy Kritskiy
1 Solution
 
NorieVBA ExpertCommented:
Try this.
Set sourceWorkbook = Application.Workbooks.Open(sourceFilename, ReadOnly:=True)

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now