Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2023, 11:15 AM
Dorin38 Dorin38 is offline Chat GPT macro that counts pictures in my document Windows 7 64bit Chat GPT macro that counts pictures in my document Office 2010
Novice
Chat GPT macro that counts pictures in my document
 
Join Date: Nov 2018
Posts: 2
Dorin38 is on a distinguished road
Question Chat GPT macro that counts pictures in my document

Hello everyone.
In order to make my work easier i need a macro that counts all the pictures in my document and inserts the count as text in a specified location. This will save me some time, because now i count the pictures manually, one by one.
So, in order to make the macro i used chat gpt and this is the code it generated, after some time i interacted with the A.I. :

Sub Nrfilefoto()
Dim imageCount As Integer
imageCount = 0
For Each shape In ActiveDocument.Shapes
If shape.Type = msoPicture And shape.Anchor.Information(wdActiveEndAdjustedPageNu mber) <> 1 Then
imageCount = imageCount + 1
ElseIf shape.Type = msoGroup Then
For Each subShape In shape.GroupItems
If subShape.Type = msoPicture And subShape.Anchor.Information(wdActiveEndAdjustedPag eNumber) <> 1 Then
imageCount = imageCount + 1
End If
Next
ElseIf shape.Type = msoAutoShape Then
If shape.Anchor.Information(wdActiveEndAdjustedPageNu mber) <> 1 Then
imageCount = imageCount + 1
End If


End If
Next
For Each InlineShape In ActiveDocument.InlineShapes
If InlineShape.Type = wdInlineShapePicture And InlineShape.Range.Information(wdActiveEndAdjustedP ageNumber) <> 1 Then
imageCount = imageCount + 1
ElseIf InlineShape.Type = wdInlineShapeCallout And InlineShape.Range.Information(wdActiveEndAdjustedP ageNumber) <> 1 Then
imageCount = imageCount + 1
End If
Next
Dim rng As Range
Set rng = ActiveDocument.Bookmarks("foto").Range
rng.Text = imageCount
ActiveDocument.Bookmarks.Add "foto", rng
Set rng = ActiveDocument.Bookmarks("file").Range
Dim pageCount As Integer
pageCount = ActiveDocument.ComputeStatistics(wdStatisticPages)
rng.Text = pageCount
ActiveDocument.Bookmarks.Add "file", rng
End Sub

So, this script counts the number of images and pages in my document and sets the text for two inserted bookmarks to the values of the count.


This is the A.I. description of the code :

VBA (Visual Basic for Applications) script used to count the number of images and pages in an active Word document. It first initializes a variable called "imageCount" to zero and then iterates through all the "Shapes" in the active document, incrementing the "imageCount" variable each time it finds a shape that is a picture, group, or AutoShape and not on the first page. Next, it iterates through all the "InlineShapes" in the active document, incrementing the "imageCount" variable each time it finds an inline shape that is a picture or callout and not on the first page. Finally, it sets the text of the "foto" and "file" bookmarks in the active document to the values of the "imageCount" and "pageCount" variables, respectively.


Now, my problem is this code doesn't count pictures that are inserted in shapes, like callout or rectangle shapes. Instead, it adds to the count all the shapes (callout, rectangle, circle) inserted in my document, no matter if they have pictures inserted inside them or not.

Does anyone have any idea of how to make this code work? Thank you in advance !

Sorry for the lenght of this post!
Reply With Quote
Reply

Tags
picture-count-chatgpt



Similar Threads
Thread Thread Starter Forum Replies Last Post
Microsoft Teams - external user chat dcmontva Misc 0 09-16-2022 03:59 AM
Microsoft Teams - How to Delete a Chat/Conversation empresslee Misc 5 05-17-2020 06:44 AM
Chat GPT macro that counts pictures in my document Macro to add captions to pictures inside word document Navis Word VBA 18 12-11-2019 03:39 PM
Chat GPT macro that counts pictures in my document Mac - Macro insert pictures in table Nina Word VBA 16 08-27-2018 01:53 AM
Chat GPT macro that counts pictures in my document Insert Pictures - Via MACRO sahrens1 Word VBA 1 07-02-2017 07:16 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:45 AM.


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