Solved

outlook vba opens workbook as read only

Posted on 2010-11-17
5
573 Views
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
objWB.Activate


End Sub

Open in new window

0
Comment
Question by:Kaps_68
  • 3
  • 2
5 Comments
 
LVL 13

Expert Comment

by:gbanik
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.
0
 
LVL 13

Expert Comment

by:gbanik
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)
.....
0
 

Author Comment

by:Kaps_68
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.
0
 
LVL 13

Accepted Solution

by:
gbanik earned 250 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
0
 

Author Closing Comment

by:Kaps_68
ID: 34158320
thanks !!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

730 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