Visual Basic Editor Error

User avatar
hlewton
GoldLounger
Posts: 2565
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Visual Basic Editor Error

Post by hlewton »

I think this is the correct forum for this because it is happening when trying to open a Word document.

I downloaded a template from Office For Mere Mortals but I have had this happen with other documents too. I have never seen this error before I got this new computer. I am not sure what I am supposed to do when this happens. I have been hitting “End” and then “Enable Editing” and then saving the document. It opens and woks fine until I copy it to another folder and I get this message again. Why am I getting this message and how do I make sure I don’t get it anymore even if I copy it to another folder? Please see attachment.

Thanks
ICE.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Visual Basic Editor Error

Post by Charles Kenyon »

The error is triggered when code is being run that requires an activedocument and there is no activedocument.
I know that I put error trapping for that into some of my Add-Ins to tell the user to open a document first.

My BarCode AddIn has such code. You are welcome to take a look at it.
http://addbalance.com/word/download.htm#BarCodeAddIn

My code produces the following error message:
00 deleteme 7.png
You do not have the required permissions to view the files attached to this post.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
hlewton
GoldLounger
Posts: 2565
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Visual Basic Editor Error

Post by hlewton »

I got to thinking and thought to attachment in this post may help. It appeared after I hit "Debug." Still I am not sure why or what I should be doing.
Ice2.jpg
You do not have the required permissions to view the files attached to this post.
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 69036
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Visual Basic Editor Error

Post by HansV »

As you can see in the screenshot in the first post, the document is in protected view, so you can't manipulate it. After clicking Enable Editing you should be able to manipulate it.
You can simply avoid the error as follows:

Code: Select all

Sub AutoOpen()
    On Error GoTo ExitHere
    If ActiveDocument.Bookmarks.Exists("OpenAt") Then
        ActiveDocument.Bookmarks("OpenAt").Select
    End If
ExitHere:
End Sub
Regards,
Hans

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Visual Basic Editor Error

Post by Charles Kenyon »

I'm not sure why an AutoOpen macro would be running when there is no ActiveDocument.
I still recommend looking at the error trapping in my Add-In.

It may be that you need to insert a delay in your procedure before the call to ActiveDocument.

Otherwise, try Hans' version of your macro.
Last edited by Charles Kenyon on 29 Jun 2020, 20:17, edited 1 time in total.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
HansV
Administrator
Posts: 69036
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Visual Basic Editor Error

Post by HansV »

Thanks for the correction, Charles. I also added () after AutoOpen.
Regards,
Hans

User avatar
hlewton
GoldLounger
Posts: 2565
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Visual Basic Editor Error

Post by hlewton »

Thanks. So I would copy and paste that in place of what is there now, correct?
Regards,
hlewton

User avatar
HansV
Administrator
Posts: 69036
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Visual Basic Editor Error

Post by HansV »

Yes, indeed.
Regards,
Hans

User avatar
hlewton
GoldLounger
Posts: 2565
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Visual Basic Editor Error

Post by hlewton »

HansV wrote:
29 Jun 2020, 20:29
Yes, indeed.
Great, thanks.
Regards,
hlewton

User avatar
hlewton
GoldLounger
Posts: 2565
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Visual Basic Editor Error

Post by hlewton »

HansV wrote:
29 Jun 2020, 20:12
Thanks for the correction, Charles. I also added () after AutoOpen.
Hans, the correction that I was going to copy and paste is gone. Not sure if yours has been edited to reflect the correction. Do I just copy he one in your post now?
Regards,
hlewton

User avatar
Charles Kenyon
3StarLounger
Posts: 320
Joined: 10 Jan 2016, 15:56
Location: Madison, Wisconsin

Re: Visual Basic Editor Error

Post by Charles Kenyon »

hlewton wrote:
29 Jun 2020, 23:40
HansV wrote:
29 Jun 2020, 20:12
Thanks for the correction, Charles. I also added () after AutoOpen.
Hans, the correction that I was going to copy and paste is gone. Not sure if yours has been edited to reflect the correction. Do I just copy he one in your post now?
I'm not Hans, but, yes. He made a couple of corrections.
Attorney Charles Kenyon

Templates in Microsoft Word http://www.addbalance.com/usersguide/templates.htm
Modifying the QAT http://addbalance.com/word/QATmodification.htm

User avatar
hlewton
GoldLounger
Posts: 2565
Joined: 24 Oct 2010, 23:39
Location: Canton, Ohio USA

Re: Visual Basic Editor Error

Post by hlewton »

Charles Kenyon wrote:
29 Jun 2020, 23:52
hlewton wrote:
29 Jun 2020, 23:40
HansV wrote:
29 Jun 2020, 20:12
Thanks for the correction, Charles. I also added () after AutoOpen.
Hans, the correction that I was going to copy and paste is gone. Not sure if yours has been edited to reflect the correction. Do I just copy he one in your post now?
I'm not Hans, but, yes. He made a couple of corrections.
Thank you.
Regards,
hlewton