Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 02-08-2021, 04:17 AM
macropod's Avatar
macropod macropod is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Instead of asking me what values properties like .LineSpacing and .LineSpacingRule return, how about selecting them in the code and pressing F1.



What you are trying to do requires a competent understanding of VBA; I don't propose to hand-feed you with the basics any competent programmer could implement or work out for themselves at every step of the journey. As I said in post #2, the code in the link was:
Quote:
code to get you started
I also warned you of the complexity of what you're trying to do.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #17  
Old 02-08-2021, 03:15 PM
Guessed's Avatar
Guessed Guessed is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Word uses 'points' as its default measurement units. There are 72 Points in an Inch.

The LineSpacingRule is the setting in the dropdown that you see in the Paragraph dialog. The computer stores the chosen option as numbers rather than text and so that it what it is returning when your macro queries this setting. You can experiment with the paragraph formatting and examine the macro results to work out what the '5' is indicating. It will be one of the following options:
  • Single
  • 1.5 Lines
  • Double
  • At Least
  • Exactly
  • Multiple
There is a reasonable chance that 5 aligns with the sixth item in this list since Word's values for LineSpacingRule most likely start with zero.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #18  
Old 02-08-2021, 10:29 PM
SamDsouza SamDsouza is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2013
Advanced Beginner
To get Returned List Values of Objects
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Paul
Indeed Lovely and neat representation with the above coding.

Quote:
What you are trying to do requires a competent understanding of VBA; I don't propose to hand-feed you with the basics any competent programmer could implement or work out for themselves at every step of the journey. As I said in post #2, the code in the link was:
No Isssues. Thanks for getting me started

Andrew
Quote:
The LineSpacingRule is the setting in the dropdown that you see in the Paragraph dialog. The computer stores the chosen option as numbers rather than text and so that it what it is returning when your macro queries this setting. You can experiment with the paragraph formatting and examine the macro results to work out what the '5' is indicating. It will be one of the following options:
Single
1.5 Lines
Double
At Least
Exactly
Multiple
There is a reasonable chance that 5 aligns with the sixth item in this list since Word's values for LineSpacingRule most likely start with zero.
Thanks for the clarifications. Much Appreciated

SamD
Reply With Quote
  #19  
Old 02-10-2021, 11:23 PM
SamDsouza SamDsouza is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2013
Advanced Beginner
To get Returned List Values of Objects
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

As I moved on

How can i get bookmark.name as returned value against that particular para. if Bookmark existed with the bookmark.name in a particular paragraph

I get error 5941" "the requested member of the collection does not exist. I've made a blunder. Shall appreciate your guidance in correcting and helping me to remove the error
Code:
Public Sub ListBasicReturnedObjects()

Dim wdActDoc As Document
Dim oBkMrk As Bookmark
Dim StrData As String, StrSty As String, Sty As Style
Dim StrStory As String
Dim i As Long
Dim strHeader As String
                                                  
Set wdActDoc = ActiveDocument
                                                    
strHeader = "Para No" & Space(5) & "Style" & Space(12) & "Alignment" & Space(2) & "Font Name" & Space(24) & "BookMark"

StrData = strHeader & vbCrLf

With wdActDoc
  For i = 1 To .Range.Paragraphs.Count
    With .Paragraphs(i)
          StrSty = .Style
          StrData = StrData & vbCr & Format(i, "#00#") & Space(8) & Mid(StrSty, 1, Len(StrSty))
                
       Set Sty = wdActDoc.Styles(StrSty)
             If Len(.Style) <= 11 Then
                StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name    '& & vbTab
              Else
                StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name
             End If
       
              
       If wdActDoc.Bookmarks.Exists("mybookmark") = False Then
          StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name & ActiveDocument.Bookmarks(i).Name 'oBkMrk.Name
        End If
    End With
   Next
  TextBox1.Text = TextBox1.Text & StrData

End With

End Sub
SamD
Reply With Quote
  #20  
Old 02-10-2021, 11:56 PM
Guessed's Avatar
Guessed Guessed is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

What are you asking for?

Your code is saying if "mybookmark" doesn't exist then tell me the name of the nth (where n = the paragraph number) bookmark. This will fail as soon as the number of bookmarks is surpassed by the number of paragraphs.

Bookmarks can be an insertion point or a range of text either within a single paragraph or across a bunch of content. So if a bookmark exists it could show a range of zero length or span multiple paragraphs.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #21  
Old 02-11-2021, 12:09 AM
macropod's Avatar
macropod macropod is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Look at the 'logic' of what you're doing:
Code:
  For i = 1 To .Range.Paragraphs.Count
    With .Paragraphs(i)
...
       If wdActDoc.Bookmarks.Exists("mybookmark") = False Then
          StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name & ActiveDocument.Bookmarks(i).Name 'oBkMrk.Name
        End If
    End With
   Next
So, you're looking through paragraphs, via a counter designated 'i'. Every time you execute the loop, you test whether a bookmark named 'mybookmark' exists anywhere in the document. If not, you tell Word to return whatever 'ActiveDocument.Bookmarks(i).Name' is - again without regard to where that bookmark might be.

Note that you're not asking Word to tell you about a bookmark in 'wdActDoc' (which may no longer be the active document) and you're not even trying to establish that a bookmark with the same index (i) as the paragraph exists before trying to get its name.

Hardly surprising you're having problems.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #22  
Old 02-11-2021, 02:00 AM
SamDsouza SamDsouza is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2013
Advanced Beginner
To get Returned List Values of Objects
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

OMG ! I've misunderstood the bookmark

What i wanted was

if paragraph had a book mark
Wanted its name and against the para number

if you see the loop
Each Para is returning the value is like .Alignment , .Range.Font.Name with this wanted addtioinally the bookMark.name if existed against the Paragrpah number

Code:
Public Sub ListBasicReturnedObjects3()

Dim wdActDoc As Document
Dim oBkMrk As Bookmark
Dim StrData As String, StrSty As String, Sty As Style, strstylen As Integer
Dim StrStory As String
Dim gapBetween As Integer
Dim i As Long, j As Long, k As Long, bTabOK As Boolean, Rng As Range
Dim bldFont As Boolean, undline As Boolean, stkThru As Boolean, strHeader As String, Pos As Integer, newPos As Integer
Dim StrRecord As String
                                                  
Set wdActDoc = ActiveDocument
                                                  '15
strHeader = "Para No" & Space(5) & "Style" & Space(12) & "Alignment" & Space(2) & "Font Name" & Space(24) & "BookMark"

StrData = strHeader & vbCrLf

With wdActDoc
  For i = 1 To .Range.Paragraphs.Count
    With .Paragraphs(i)
          StrSty = .Style
          StrData = StrData & vbCr & Format(i, "#00#") & Space(8) & Mid(StrSty, 1, Len(StrSty))
                
       Set Sty = wdActDoc.Styles(StrSty)
             If Len(.Style) <= 11 Then
                StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name   
              Else
                StrData = StrData & Space(8) & .Alignment & Space(8) & .Range.Font.Name
             End If

What should be the code here in this loop if there is a book mark in the Para of Active document
BkMark-Para2 is the bookmark.name. As Para 2 was selected and Book mark name was given as BkMark-Para2
Please  see the quoted representation 
       
       
    End With
   Next
  TextBox1.Text = TextBox1.Text & StrData

End With

End Sub
Quote:
Para No Style Alignment Font Name BookMark

001 Normal (Web) 0 Arial
002 Normal (Web) 0 Arial BkMark-Para2
003 Normal (Web) 0 Times New Roman
004 Normal (Web) 0 Arial
005 Normal (Web) 0 Arial
006 Normal (Web) 0 Arial
007 Normal (Web) 0 Arial
008 Normal (Web) 0 Arial
009 Normal (Web) 0 Arial
010 Normal (Web) 0 Arial
011 Normal (Web) 0 Arial
012 Normal (Web) 0 Arial
013 Normal 0 Arial
SamD
Reply With Quote
  #23  
Old 02-11-2021, 03:08 PM
Guessed's Avatar
Guessed Guessed is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This is how I would do it. Add these lines where you indicated
Code:
          For Each aBkmk In .Range.Bookmarks
            StrData = StrData & vbTab & aBkmk.Name
          Next aBkmk
You will also need to declare the variable at the top
Dim aBkmk As Bookmark
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #24  
Old 02-13-2021, 01:48 AM
SamDsouza SamDsouza is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2013
Advanced Beginner
To get Returned List Values of Objects
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Thanks Andrew

I did the correction. and now clear on Bookmark

As further i move on with few trials and tests. What i observed was that
another document with total nos paras. were 244 but some ridiculous returned value
of font size Format(.Range.Font.Size, "##")

Font size should display its size in 2 digits but here few paras. showed the .range.font.size as 9999999
Font name is Times New Roman and size were displayed as 18,12,11... and 9999999
How can the size be retained to 2 digit

Code:
If stkThru = True Then                                                                                                                                
         StrData = StrData & stkThru & Space(18) & Format(.Range.Font.Size, "##") & Space(18)        
       Else
         StrData = StrData & stkThru & Space(18) & Format(.Range.Font.Size, "##") & Space(18)      
End If
SamD
Reply With Quote
  #25  
Old 02-13-2021, 03:17 AM
Guessed's Avatar
Guessed Guessed is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

When a paragraph has more than one font size in it, the 'range' size font will return an undefined value which shows up as a blank font size in the GUI - but in VBA this will show as a number like 999999. There could be a large number of font sizes and typefaces in a single paragraph. You can augment the code to query every location inside a paragraph if an undefined value is encountered for the overall size or typeface but the value of that is dubious.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #26  
Old 02-13-2021, 04:31 AM
SamDsouza SamDsouza is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2013
Advanced Beginner
To get Returned List Values of Objects
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Thanks Andrew for the clarification.

Quote:
You can augment the code to query every location inside a paragraph if an undefined value is encountered for the overall size or typeface but the value of that is dubious
This is intresting.
Any thread reference you could recommend where i can implement the same in my coding.

SamD
Reply With Quote
  #27  
Old 02-18-2021, 01:43 AM
SamDsouza SamDsouza is offline To get Returned List Values of Objects Windows 10 To get Returned List Values of Objects Office 2013
Advanced Beginner
To get Returned List Values of Objects
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Will it be possible to control the length of wdUndefined number 9999999
when 9999999 is displayed it occupies un-wanted space and the structure is disturbed.

In Any manner Can we shorten the 9999999 to 99. if yes then how ?
and even if not and still displayed as 9999999 then how can i get equal spacing after
9999999 because other fonts are displayed with 2 digit size.

SamD
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple found values from five sheets, multiple returned values in sheet six? irisha Excel Programming 26 09-30-2016 01:20 AM
To get Returned List Values of Objects Macros to move objects prevents moving same objects with arrow keys BruceM Word VBA 1 03-10-2015 08:20 AM
List of Objects for CreateObject excelledsoftware Excel Programming 4 09-14-2014 08:47 PM
To get Returned List Values of Objects Query list of objects and properties in VBA bshawnr Word VBA 1 08-22-2013 11:03 PM
Pivot Table:delete zero values when using calculated objects Serge 007 Excel 1 06-05-2013 11:47 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:10 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