NPK
NPK

Reputation: 33

VBA to enable editing

I'm trying to download an attachment from a secured site and open it using VBA.

While i'm trying to activate the workbook ( $workbook(Wb_name).Activate ), it throws some error and when I click on enable editing manually and try executing the same code it works fine.

Is there a way to enable the workbook from protected view before activating it.

Note : I have extracted the file name from the webpage. So don't have to bother about "Wb_name".

Upvotes: 3

Views: 24145

Answers (2)

RHOOPH
RHOOPH

Reputation: 94

If the workbook you are trying to manipulate is the ActiveWindow then this code should help,

 If Not Application.ActiveProtectedViewWindow Is Nothing Then
     Application.ActiveProtectedViewWindow.Edit
 End If

Upvotes: 6

RajSharma
RajSharma

Reputation: 1971

One possibility is to change the macro security settings programmatically to the lowest before you open the Excel workbook. After manipulating your data, re-enable the previous setting of the macro security

Public Sub MySubroutine()
Dim lSecurity As Long

lSecurity = Application.AutomationSecurity
Application.AutomationSecurity = msoAutomationSecurityLow

'''''''''''''''''''''
'   Run code here   '
'''''''''''''''''''''

Application.AutomationSecurity = lSecurity

End Sub

this link may also help you..

Upvotes: 1

Related Questions