OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Thread Tools Search this Thread Display Modes
Old 16-12-2012, 08:53
FaneDuru FaneDuru is offline
Join Date: May 2012
Posts: 35
Exclamation Set the VBProject of ActiveDocument if Template

How can I find the VBProject of the active document in case of template (Untitled-1, 2, 3...).
For a compiled document I can do that using the next code:
Dim VBEt As VBE, VBPr As vbide.VBProject, ActVBPr As vbide.VBProject
   Dim NameD As String
   Set VBEt = Application.VBE
    For Each VBPr In VBEt.VBProjects
        NameD = Right(VBPr.BuildFileName, Len(VBPr.BuildFileName) - _
                                            InStrRev(VBPr.BuildFileName, "\"))
        NameD = Left(NameD, Len(NameD) - 4)
        If NameD = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4) Then _
                                                   Set ActVBPr = VBPr: Exit For
    If Not ActVBPr Is Nothing Then Debug.Print ActVBPr.Name
But how can I find in VBE the VBProject of the active Template document?
For each such document BuildFileName returns 'VBAProject.dll'...

I mean I need something like VBA Excel solves in this way:
 Set VPPr = ActiveWorkbook.VBProject
Thanks in advance!

Last edited by FaneDuru; 17-12-2012 at 02:35.
Reply With Quote
Old 09-01-2013, 13:46
FaneDuru FaneDuru is offline
Join Date: May 2012
Posts: 35

I can now 'mark' the template VBAProject using the next code in DocumentNew event of ThisMacroStorage (GlobalMacros):
(Of course referencing "Microsoft Visual Basic for Application Extensibility 5.3")
Private Sub GlobalMacroStorage_DocumentNew(ByVal Doc As Document, ByVal FromTemplate As Boolean, ByVal Template As String, ByVal IncludeGraphics As Boolean)
       Application.VBE.VBProjects(Application.VBE.VBProjects.Count).Name = _
                                                     Replace(ActiveDocument.Name, "-", "_")   
End Sub
Then, VBAProject of ActiveDocument can be set with the next piece of code:
Dim V As VBProject, VBAProjectOfActDoc As VBProject
 For Each V In Application.VBE.VBProjects
    If V.Name = Replace(ActiveDocument.Name, "-", "_") Then Set VBAProjectOfActDoc = V: Exit For
Since the document name is present between parenthesis near the VBProject name I suppose that it can be somehow directly obtained. I just do not know how...

Last edited by FaneDuru; 10-01-2013 at 08:38.
Reply With Quote

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
RunMacro in the ActiveDocument pafi Macros/Add-ons 1 25-01-2010 09:45
Using ActiveDocument.SaveAs (c#) dlpfis CorelDRAW/Corel DESIGNER VBA 2 28-07-2009 08:39
Template files rbentley General 1 20-08-2008 13:45
Help with ActiveDocument.PublishToPDF pbisson Corel Photo-Paint VBA 5 03-01-2007 20:37
Help with ActiveDocument.PublishToPDF pbisson Macros/Add-ons 0 15-12-2006 16:27

All times are GMT -5. The time now is 02:35.

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com