Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
What am I missing (Opening Workbooks) | Excel Programming | |||
Excel2007; workbooks.count is not counting all open workbooks | Excel Programming | |||
Compare two workbooks and Copy missing data | Excel Programming | |||
workbooks.open function fails to open an existing excel file when used in ASP, but works in VB. | Excel Programming | |||
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 | Excel Programming |