outlook vba opens workbook as read only

Posted on 2010-11-17
Medium Priority
Last Modified: 2012-05-10
I am trying to open an Excel workbook from outlook. However for some reason the book opens as read only. I need to be able to write to the file:-

Option Explicit

'outlook objects

Public oNameSpace As Outlook.NameSpace
Public oInboxItem As Variant
Public oFolder As Outlook.MAPIFolder
Public oMsg As Object

'excel objects

Public objexcel As Excel.Application
Public objWB As Excel.Workbook
Public objFSO As Scripting.FileSystemObject
Public excel_filename As String

Sub Extract_Reports()
'extracts reports for HomeExpert

Set objFSO = CreateObject("Scripting.FileSystemObject")

'opens the excel workbook

Call open_workbook

Call extract_outlook_info

Call close_workbook

End Sub

Public Sub open_workbook()
'opens the Excel workbook
Dim excel_path  As String

excel_path = "C:\01 simplyspreadsheets\63 home expert\"
excel_filename = "master file.xlsx"

MsgBox excel_path & " " & excel_filename

Set objexcel = CreateObject("excel.application")
Set objWB = objexcel.Workbooks.Open(excel_path & excel_filename, ReadOnly:=False)

objexcel.Visible = True

End Sub

Open in new window

Question by:Kaps_68
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 13

Expert Comment

ID: 34157551
None of your code can do that (force an excel file to open read-only). Are u sure the file isnt read-only before u tried to open it thru the above code? Thats the only way it could have.
LVL 13

Expert Comment

ID: 34157589
Try this code... this would change the file attributes to normal before opening it.

excel_path = "C:\01 simplyspreadsheets\63 home expert\"
excel_filename = "master file.xlsx"

SetAttr excel_path & " " & excel_filename, vbNormal
MsgBox excel_path & " " & excel_filename

Set objexcel = CreateObject("excel.application")
Set objWB = objexcel.Workbooks.Open(excel_path & excel_filename, ReadOnly:=False)

Author Comment

ID: 34158101
thanks - that gives a file not found error. However the file is there. I have checked the properties of the file and  it is not read only.
LVL 13

Accepted Solution

gbanik earned 1000 total points
ID: 34158246
Sorry how could I miss it? There is a space in code...
use the following
SetAttr excel_path & excel_filename, vbNormal

Author Closing Comment

ID: 34158320
thanks !!

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this step by step procedure, you will come to know the details of creating an Outlook meeting in 2007, 2010, 2013 & 2016.
In this article I discuss my selections of the Top Four free Outlook OST File Viewers available. Open, view and read even damaged OST files by using these tools. They all provide a clear preview of all data such as emails, notes, tasks, calendars, e…
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question