• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

outlook vba opens workbook as read only

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
Kaps_68
Asked:
Kaps_68
  • 3
  • 2
1 Solution
 
gbanikCommented:
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
 
gbanikCommented:
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
 
Kaps_68Author Commented:
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
 
gbanikCommented:
Sorry how could I miss it? There is a space in code...
use the following
SetAttr excel_path & excel_filename, vbNormal
0
 
Kaps_68Author Commented:
thanks !!
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

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