If I try to use a document event but it works only in Untitled ones. After save, when I reopen it I am asked about enabling macros, I press Enable but nothing happens. Any of its events do not work. In IDE the name of the file does not appears in parenthesis after VBAProject (in case of events existing)... It looks it is hidden. I mean enumerating VBAProjects in VBA, its name appears like being a VBProject.
Is that a general problem of X8 (maybe a strange security one...) or only my installation has a problem?
Is it something to be done in order to activate events?
I tried some workaround which works but also in strange circumstances. I use a reference at 'Microsoft Visual Basic for Applications Extensibility 5.3' and that gives me the possibility to programmatic copy an event from a document/GSM to another document. When that document does not have a path (type Untitled) it works. If I save it all event code stays there but stops working. If I copy such an event in a document (saved) not having VBProject (not any VBA) it is not working, too.
Another annoying issue is the next:
If you save a document having an event code and after that you delete that code, somehow some VBA garbage remains inside that document. When I open it I am prompt about macro Enabling, even if not a line of VBA code exists any more. On top of that, if you have a big document with more then 100 pages, that in-existing VBA project (garbage) loads first and the document itself loads only after that. You cannot see the message asking about Enabling macro. If you call a function from a button outside VBE, CorelDRAW crashes... In such cases I learned it is necessary to play with Ctrl + Tab until I find the message about macro Enabling and press one of its buttons. Otherwise corelDRAW crashes...
Is there a way to clean the document of its VBA garbage in order not to be prompted regarding macro enabling?
Thanks in advance!
P.S. Any idea about whatever issue presented here will be well appreciated, even strange approach will be presented...
This also appens in CorelDRAW 2017. I have a Template with some VBA code and crashes CDR if I save with the macros and then try to re-open the file.This issue comes from X8.
I'm trying to get to a solution too, if I came up with something i will post it here.
In my previous X7 installation, document events Worked!
If it crashes I am afraid that your code contains something bothering Corel. If not confidential can you post the code here?
The is that my Template is now without any code.But I still have the option to "save with embeded VBA project"
Here is my code:
Private Sub Document_BeforeSave(ByVal SaveAs As Boolean, ByVal FileName As String) Dim ano As String ano = Year(Date) ActiveDocument.Metadata.Title = ActivePage.Layers("Obra").Shapes("NObra").Text.Story.Words(1) ActiveDocument.Metadata.Subject = ActivePage.Layers("Obra").Shapes("Cliente").Text.Story ActiveDocument.Metadata.Keywords = ActivePage.Layers("Obra").Shapes("Cliente").Text.Story ActiveDocument.Metadata.Author = ActivePage.Layers("Obra").Shapes("Desenhador").Text.Story ActiveDocument.Metadata.Copyright = ano + " MyCompany"End Sub
Private Sub Document_PageActivate(ByVal Page As Page) ActiveDocument.WorldScale = 0 & ActivePage.Layers("Obra").Shapes("Escala").Text.StoryEnd Sub
Like you know I cannot test any event in a document so I think and work blind...
Firstly you must check if your event is fired. Change everything with just MsgBox "It works..."
If it works I'm just thinking maybe is possible that the layer not to keep its name. So I would suggest to check that prior to the main code working:
1 2 3 4 5 6 7 8 9 10 11 12
Dim ano As String, L As Layer ano = Year(Date) For Each L In ActivePage.Layers If L.Name = "Obra" Then Stop ActiveDocument.Metadata.Title = ActivePage.Layers("Obra").Shapes("NObra").Text.Story.Words(1) ActiveDocument.Metadata.Subject = ActivePage.Layers("Obra").Shapes("Cliente").Text.Story ActiveDocument.Metadata.Keywords = ActivePage.Layers("Obra").Shapes("Cliente").Text.Story ActiveDocument.Metadata.Author = ActivePage.Layers("Obra").Shapes("Desenhador").Text.Story ActiveDocument.Metadata.Copyright = ano + " MyCompany" End If Next
If the layer will be found the code will stop and please press F8 in order to see the line which Corel doesn't like...
Coreldraw retains the layer name. That's not a problem.
Problem is that if we have a macro in the Document and then save it. If we open it next CorelDRAW crashs.
Rob,
You need to set break points in any of the Events code, that way you can step through it and see which line is crashing CorelDRAW.
-Shelby
So, events should work in X8 64bit? Do you have an idea about the problem of my installation even if I uninstalled and reinstalled ii several times? What would be good to try?
And what about document cleaning of VBA garbage after deleting all VBA code...
Try to download this document:www.dropbox.com/.../171026_01.cdr When I click on it in the explorer (Corel isn't running) X8 is starting with this document.
In the ObjectBrowser I see some pages and some layers. When I toggle between, nothing happens.
Then I try to open the VBA-Editor (<Alt>-<F11>) I've been asked If I trust those macros. Then I agree.
Afterwards each LayerChange causes at least one MessageBox.
When I close this document (not Corel!) and open it again either from the Recent Files or with clicking on it in the explorer I've been directly asked, if I trust the macros - I agree again, but then: Nothing happens.It seems to be necessary to open the document directly with Corel, then the events will work, otherwise they are not recognized for any un-understandable reason
I understood what you are saying from your (own) previous post. I tried it and it doesn't work in my case. And I do not know what to do in order to solve this events not working problem.
I also cannot how to solve the VBA garbage problem. When I saved a document with some VBA code and after a while I delete all code it keep asking about Enabling Macros even if there is not any code line inside. This shouldn't be so annoying if in case of big size documents (more then 100 pages) the warning message is loaded first and document itself after that, the message not being visible any more. If you try to start a macro Corel crashes...
I tried the events in the document I offered to you also on my laptop where I also have Corel installed on D:\, and there it also worked like described.I did also more tests and came to that conclusion:Something happens, when you open the VBA-Editor (or activate the macros the first time). If you open one or more documents with events nothing happens unless you open the VBA-Editor. Then the events for the open documents work. If you open a document after the VBA-Editor had been opened, the events for this document will not work, but the events for the previously opened documents.In my use case the preconditions are given: My batch takes care, that the needed documents are open. Then - when I move the mouse the first time over my icons - I get asked (due to my macro security setting 'Medium'), if I trust the macros. I think, this step will do the same as I do when I - without Macro-security -open the VBA-Editor for the first time.Maybe you check, if this behaviour is also valid in your environment.I already opened for this behaviour a ticket, maybe you do the same, so the probability that they will change this is higher Regarding the 'VBA-Garbage': I can not remember that I had the need to remove VBA-Code from a document.
Maybe my way of programming is slightly different to yours, I also don't know, if this method is possible for your tasks:When I have the need to create more pages under Corel, I always work with two documents: One Document containing only the macros with in general only one page with default layers. This document then creates a second document with many pages I have then e.g. to print. So my documents with VBA-Code are pretty small, the other containing a lot of graphics over a lot of pages may become huge, but I need only to open then for the current session, but do not need then in general later. So my program documents are not affected by the size of their output.
Maybe you think about this method before you start your next project.
I tested in the way you suggested but events do not work in any circumstance! I tried it with Security Low level but also for nothing.
I do not use macros in big sizes documents. I have one document with labels containing more then 100 pages. In order to make the labels I use an automation of course. In a GMS file I have a form which needs to have some text boxes updated with page sizes when a different page is activated. I do that writing (on the fly) code in the document pageActivated event. This code is able to write in the Form text boxes. After doing the job I delete the code but some VBA garbage remains so each time I open the document, even if it does not contain any line of VBA code I'm prompted to enable macros or not...