Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-16-2024, 05:08 PM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default WordVBA: list object in .dotm file

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
Reply With Quote
  #2  
Old 07-17-2024, 04:17 AM
Italophile Italophile is offline WordVBA: list object in .dotm file Windows 11 WordVBA: list object in .dotm file Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

To list the "objects" you will first need to know what type of "objects" they are.
Reply With Quote
  #3  
Old 07-17-2024, 05:07 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 07-17-2024, 05:18 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

I found it..
Reply With Quote
  #5  
Old 07-17-2024, 06:06 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 07-17-2024, 09:27 AM
Italophile Italophile is offline WordVBA: list object in .dotm file Windows 11 WordVBA: list object in .dotm file Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

UserForms are modal unless specified. Use

Code:
UserFormName.Show vbModeless
Reply With Quote
  #7  
Old 07-17-2024, 11:38 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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••••ˇˇˇˇ
Reply With Quote
  #8  
Old 07-17-2024, 11:53 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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?
Reply With Quote
  #9  
Old 07-18-2024, 12:31 AM
Italophile Italophile is offline WordVBA: list object in .dotm file Windows 11 WordVBA: list object in .dotm file Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

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.
Reply With Quote
  #10  
Old 07-18-2024, 11:58 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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
Reply With Quote
  #11  
Old 07-19-2024, 04:16 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

***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.*** That is what I've been looking for.
Thanks!!
-An
Reply With Quote
  #12  
Old 07-25-2024, 05:42 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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
Reply With Quote
  #13  
Old 07-25-2024, 07:54 AM
Italophile Italophile is offline WordVBA: list object in .dotm file Windows 11 WordVBA: list object in .dotm file Office 2021
Expert
 
Join Date: Mar 2022
Posts: 554
Italophile is just really niceItalophile is just really niceItalophile is just really niceItalophile is just really nice
Default

The First Page Footer will only show in the document if Different First Page has been selected in the Page Layout dialog.
Reply With Quote
  #14  
Old 07-25-2024, 09:33 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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
Reply With Quote
  #15  
Old 07-25-2024, 11:30 AM
annguye2 annguye2 is offline WordVBA: list object in .dotm file Mac OS X WordVBA: list object in .dotm file Office 2021
Novice
WordVBA: list object in .dotm file
 
Join Date: Jul 2024
Posts: 22
annguye2 is on a distinguished road
Default

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
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
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
WordVBA: list object in .dotm file Editing .dotm/.dotx/dot file martinlest Word 9 10-09-2013 01:57 PM
WordVBA: list object in .dotm file Macros being stripped from dotm file Brian Muth Word 1 10-09-2012 10:00 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:52 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft