Share via

Poisoned declare statement

Anonymous
2022-02-16T22:47:48+00:00

This DECLARE statement (part of a set of statements in my declarations) used to work just fine in Excel for Office 365. Now, putting it into a brand-new spreadsheet--just this line alone--causes sharing and access violations that prevent me from even saving the file:

Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _

            (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

Again--this single line of code, inserted into a VBA module that otherwise HAS NOTHING ELSE IN IT, causes the problem. I have already tried the modification below, and that doesn't help either. Can someone help? Thanks!

#If VBA7 Then

Private Declare PtrSafe Function apiShowWindow Lib "user32" Alias "ShowWindow" _ (ByVal hWnd As LongPtr, ByVal nCmdShow As Long) As Long

#Else

Private Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _ (ByVal hWnd As Long, ByVal nCmdShow As Long) As Long

#End If

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2022-02-17T08:16:18+00:00

    If you can't save a new file with just that line means for me you have some trouble with your virus scanner or other 3rd party security tools.

    Please follow these steps:

    Close Excel
    Press and hold the CTRL key
    Open Excel
    Wait for a message to appear and ask for "Safe Mode"
    Release the CTRL key
    Click Yes
    After Excel opens
    Test the behavior

    Andreas.

    Was this answer helpful?

    0 comments No comments