![]() |
#1
|
|||
|
|||
![]()
Hi All,
I am just a few hours with Word-VBA. Can someone please show me how to list all added objects on a .dotm file? I have a template with many added object (added in manually). And now I have to list all of them in a dropdown box I really appreciate for any help. Thanks, An Nguyen |
#2
|
|||
|
|||
![]()
To list the "objects" you will first need to know what type of "objects" they are.
|
#3
|
|||
|
|||
![]()
Thanks for quick reply, Italophile. The objects were created or embedded from .doc template file (*.dotm)
And I've researched and found it's wdInlineShapeEmbeddedOLEObject type. Do you know how to open the file with VBA code if we have the index number? Thanks, An Nguyen |
#4
|
|||
|
|||
![]()
I found it..
![]() |
#5
|
|||
|
|||
![]()
Now I have new issue..
Once the template is opened, here are what I found: - The UserForm is on the top of open Template, so I can't edit the template - If I close UserForm, leave the current template open and reopen the UserForm(By compiling the VBA code) I can't not open any template on .dotm file. Any ideas how to handle this situation? Thanks in advance. |
#6
|
|||
|
|||
![]()
UserForms are modal unless specified. Use
Code:
UserFormName.Show vbModeless |
#7
|
|||
|
|||
![]()
Thanks.
I am using Mac, and it can't open the UserForm in design view.. So I can't apply your suggestion. How do you find the UserForm name in the code? I only have this in Form Initialize stage Private Sub UserForm_Initialize() With TemplateName .AddItem "Template 1" .AddItem "Template 2" .AddItem "Template 3" .AddItem "Template 4" .AddItem "Template 5" .AddItem "Template 6" End With End Sub••••ˇˇˇˇ |
#8
|
|||
|
|||
![]()
Ok so I found the way to look for the UserForm Name
Debug.Print "Form Name: " & Me.Name But when using what you suggested, Templat_Selection.Show vbModeless it's jump into error handler ***Error pulling document! ErrHandler: Case 0004 **** Any idea why it's bad? |
#9
|
|||
|
|||
![]()
It is impossible to debug a single line of code. Post your full code and someone may be able to help you.
I know there can be issues specific to running code on a Mac, but as I don't have access to one I can't test. |
#10
|
|||
|
|||
![]()
Sorry for the late reply.
Here is what I've found: - The Userform Show on Initialize, and once it shows..we can't set its modal status inthe code - There's a work around for it. For any Click event, we can Hide, and then Show with Modeless condition set I am fairly new to VBA with WORD, so thanks a lot for your suggestion, and patience. -An |
#11
|
|||
|
|||
![]()
***To list all added objects in a .dotm file and populate them in a dropdown box using Word-VBA, you can iterate through the shapes collection of the document.***
![]() ![]() Thanks!! -An |
#12
|
|||
|
|||
![]()
Hi,
I am trying to copy the footer from one document to another. And here is what my code (I only try to copy the first page footer) Sub CopyFootersForFirstPage() ' works Dim docTemplate As Document Dim strTemplate As String Dim footer1 As HeaderFooter Dim footer2 As HeaderFooter Dim doc As Document Application.ScreenUpdating = False Set doc = ActiveDocument strTemplate = "Some.docx" ' successfully open Set docTemplate = Documents.Open(strTemplate) ' successfully open Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterFirs tPage) Set footer2 = doc.Sections(1).Footers(wdHeaderFooterFirstPage) footer1.Range.Copy 'Debug.Print "FootnFORE COPY first page : " & footer1.Range.Text footer2.Range.Paste Debug.Print "Foot2: " & footer2.Range.Text ' foot2 is printed in immeidate windows 'Set footer1 = Nothing 'Set footer2 = Nothing ' Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterFirs tPage) ' Set footer2 = doc.Sections(1).Footers(wdHeaderFooterPrimary) ' Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterPrim ary) ' Set footer2 = doc.Sections(1).Footers(wdHeaderFooterPrimary) Application.ScreenUpdating = True docTemplate.Close False End Sub it prints out the footers (target doc) but it's not display in on the doc. Can you please point me out why? Thanks, An Nguyen |
#13
|
|||
|
|||
![]()
The First Page Footer will only show in the document if Different First Page has been selected in the Page Layout dialog.
|
#14
|
|||
|
|||
![]()
Thanks, I followed the instructions AND found it works.
However: - It works when on a target document that is empty. - For the document that fully filled with information, it's showing error on paste. My guess is that it needs time for completing the edit at PASTE action, but I don't know how to deal with it. Please advise! Here is the part of code where it is stuck (Bolded) and the error message is "(run time error 4505, This method or property is not available because the current selection is locked for editing" ' First Page Footers copy and paste Set footer1 = docTemplate.Sections(1).Footers(wdHeaderFooterFirs tPage) Set footer2 = doc.Sections(1).Footers(wdHeaderFooterFirstPage) doc.PageSetup.DifferentFirstPageHeaderFooter = True footer1.Range.Copy footer2.Range.Paste Set footer1 = Nothing Set footer2 = Nothing |
#15
|
|||
|
|||
![]()
I found something that maybe the problem to stop user from editing the first page footer.
When trying to or modify with VBA, it says the section is protected, not allows to remove or edit. I ran the same thing with First Page Header then it works so it might be the problem. Please let me know what you think Thanks, An Nguyen |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to determine Windows Zoom level when using multiple monitors with different settings in WordVBA? | skarden | Word VBA | 0 | 09-12-2023 03:49 AM |
instance a new dotm file from a Word dotm file and save with new file name | David Peck | Word VBA | 3 | 08-18-2023 06:47 AM |
I have Error at File System Object: Cant find object or lib | johndrew | Word VBA | 3 | 07-05-2018 08:46 PM |
![]() |
martinlest | Word | 9 | 10-09-2013 01:57 PM |
![]() |
Brian Muth | Word | 1 | 10-09-2012 10:00 PM |