LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default What am I missing - Workbooks.Open

OK, what am I missing folks. I'm using this to open a workbook as ReadOnly
and so I can edit it at a different time. The workbook I'm trying to open
has VBA code in it and I'm trying to open as Read Only. I've recently had
to add the automation security lines so I don't get a message to enable
macros when I open a workbook that contains them. I don't have the caps
lock key pressed either. If myReadOnly = FALSE, it opens the workbook and
execution ends.

I've done this this way in another workbook and it worked fine.

FWIW, I'm also having issues saving a powerPoint presentation that I used to
be able to save programmatically. Could my laptop have gremlins?

Thanks,

Barb Reinhardt


Option Explicit
Sub OpenWorkbook(myWB As Excel.Workbook, myReadOnly As Boolean)
Dim sFile As String
Dim ShortName As String
Dim autoSecurity As MsoAutomationSecurity

With Application.FileDialog(msoFileDialogFilePicker)
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "Excel Files", myXLFilter
.FilterIndex = 1
.Title = "Please Select File to open"
If .Show = False Then Exit Sub
sFile = .SelectedItems(1)
End With

ShortName = Right(sFile, Len(sFile) - InStrRev(sFile, "\"))

Set myWB = Nothing
On Error Resume Next
Set myWB = Workbooks(ShortName)
On Error GoTo 0

If myWB Is Nothing Then
autoSecurity = Application.AutomationSecurity
If myReadOnly Then
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Set myWB = Workbooks.Open(sFile, ReadOnly:=True)
Application.AutomationSecurity = autoSecurity
Else
Application.AutomationSecurity = msoAutomationSecurityForceDisable
Set myWB = Workbooks.Open(sFile)
Application.AutomationSecurity = autoSecurity
End If
Debug.Print myWB.Name

Else
'No action
End If

End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What am I missing (Opening Workbooks) Barb Reinhardt Excel Programming 3 August 14th 08 02:55 AM
Excel2007; workbooks.count is not counting all open workbooks greg.campeau Excel Programming 2 August 2nd 08 08:37 PM
Compare two workbooks and Copy missing data Naba Excel Programming 0 June 29th 06 06:59 AM
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. san Excel Programming 1 January 3rd 06 03:22 AM
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed Frank Jones Excel Programming 2 June 15th 04 03:21 AM


All times are GMT +1. The time now is 02:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"