Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #16  
Old 03-08-2020, 11:35 PM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Thank you sir, I did put in right place but realised very late for the below syntax
Quote:
Const wdHeaderFooterPrimary As Long = 1
But now i get Error as User Type Not defined marked in bold below when implementing the same to insert the image
Code:
Dim oSec As Section
Dim oHeaderFooter As HeaderFooter
Dim oLogo As inlineshape
        
Set oSec =  ActiveDocument.Sections
        Set oHeaderFooter = oSec.Headers(wdHeaderFooterPrimary)
        With oHeaderFooter.Range
            .ParagraphFormat.Alignment = wdAlignParagraphRight
                   Set oLogo = .InlineShapes.AddPicture(Filename:="C:\FORMS\1-Seal.jpg", LinkToFile:=False, SaveWithDocument:=True)
        
        End With
        With oLogo
            .Height = 75
            .Width = 100
        End With
SamD
Reply With Quote
  #17  
Old 03-09-2020, 12:42 AM
macropod's Avatar
macropod macropod is offline Create a Word Document with VBA Windows 7 64bit Create a Word Document with VBA Office 2010 32bit
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

You don't need:
Code:
Dim oSec As Section
Dim oHeaderFooter As HeaderFooter
All you need is something like:
Code:
Const wdAlignTabRight As Long = 2
Dim oLogo As Object
'….
  With .Sections.First.Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Range
    .Text = "Footer Note" & vbTab
    .Paragraphs(1).TabStops.Add wdApp.InchesToPoints(7.5), wdAlignTabRight
    Set oLogo = .InlineShapes.AddPicture("C:\FORMS\1-Seal.jpg", False, True, .Characters.Last)
    With oLogo
      .Height = 75
      .Width = 100
    End With
  End With
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #18  
Old 03-09-2020, 03:47 AM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Was Succesfull At the end when i tried the following which i think after the whole document is made and then insert footnote with following code with your reply on the following
Forum Solved: Image in Footer behind text

but somehow niehther the width changes height changes of the image nor the image goes behind the text

also error "variable" not defined was seen when implemented with InchesToPoints(1) or CentimetersToPoints(4.5)


Code:
'''''Set wdDoc = wdApp.Documents.Add

Dim shp As Shape
With wdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range
.Paragraphs.Alignment = wdAlignParagraphRight

   Set shp = .inlineshapes.AddPicture(Filename:="C:\FORMS\1-Seal.jpg", LinkToFile:=False, SaveWithDocument:=True)''', Height:=45, Width:=55)
       With shp
                .WrapFormat.Type = wdWrapBehind
                .LockAspectRatio = msoTrue
                .Height = 20
                .Width = 20 'InchesToPoints(1) '20  'CentimetersToPoints(4.5)
        End With
.collapse Direction:=0
End With
SamD
Reply With Quote
  #19  
Old 03-09-2020, 04:05 AM
macropod's Avatar
macropod macropod is offline Create a Word Document with VBA Windows 7 64bit Create a Word Document with VBA Office 2010 32bit
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

Well, you're now not working with an inlineshape, but one you're converting to a floating shape. It's impossible to know how to code things when you keep changing the parameters.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #20  
Old 03-09-2020, 04:28 AM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Extremely Sorry Sir,

I got error when you posted the following code
at same point InchesToPoints(7.5) Variable not defined.
Quote:
Const wdAlignTabRight As Long = 2
Dim oLogo As Object
'….
With .Sections.First.Footers(wdHeaderFooterPrimary).Ran ge.Paragraphs(1).Range
.Text = "Footer Note" & vbTab
.Paragraphs(1).TabStops.Add InchesToPoints(7.5), wdAlignTabRight
Set oLogo = .InlineShapes.AddPicture("C:\FORMS\1-Seal.jpg", False, True, .Characters.Last)
With oLogo
.Height = 75
.Width = 100
End With
End With
Then i explored the net and found the VBA link with your reply which i thought would be useful Because my Image Size was big and rather did not fit in foot note and probably attractive if the img goes behind the text which i never thought of.

I am novice in basic learning phase with VBA word.
Reply With Quote
  #21  
Old 03-09-2020, 08:38 AM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

I am still confused between .inlineshapes and Floating shapes and messed up.

my image size is 6.32 cm H and 5.27 cm W. I would like to resize to 25% of left sizes provided and Image to be provided behind text.

.Paragraphs(1).TabStops.Add InchesToPoints(7.5), wdAlignTabRight
this poped up with error hiliting InchesToPoints(7.5) "Sub or Function Not defined
Sir indeed your coding was practical to what i desired
Quote:
All you need is something like:
Code:
Const wdAlignTabRight As Long = 2
Dim oLogo As Object
'….
With .Sections.First.Footers(wdHeaderFooterPrimary).Ran ge.Paragraphs(1).Range
.Text = "Footer Note" & vbTab
.Paragraphs(1).TabStops.Add InchesToPoints(7.5), wdAlignTabRight
Set oLogo = .InlineShapes.AddPicture("C:\FORMS\1-Seal.jpg", False, True, .Characters.Last)
With oLogo
.Height = 75
.Width = 100
End With
End With
Reply With Quote
  #22  
Old 03-09-2020, 03:32 PM
macropod's Avatar
macropod macropod is offline Create a Word Document with VBA Windows 7 64bit Create a Word Document with VBA Office 2010 32bit
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

You've omitted the wdApp. reference.
In any event, everything I provided for inlineshape insertion is all irrelevant now, because of:
Quote:
Originally Posted by SamDsouza View Post
my image size is 6.32 cm H and 5.27 cm W. I would like to resize to 25% of left sizes provided and Image to be provided behind text.
A picture located behind the text cannot be an inline shape. So what you said here:
Quote:
Originally Posted by SamDsouza View Post
And a small image if i could insert at Right at Footer note.
isn't really what you want at all. I'm done wasting time on this: use a template!
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #23  
Old 03-10-2020, 05:09 AM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Sir, thank you so much Indeed your inputs and guidance were really helpful.
I achieved what i desired and the page representation has come really beautifully and correctly. With your strong suggestion will use template.

My last question on this thread as coding has gone much more into it.
How about proper reference or syntax in footernote with its respective paragraph number have few characters bold in them.

I used the following No Error but nothing displayed in as bold was not triggered. I feel somewhere i've not given proper reference
Code:
Dim rngCharcs As Object
Set rngCharcs = wdDoc.Sections.First.footers(wdHeaderFooterPrimary).Range   
 rngCharcs(rngCharcs.Paragraphs(1).Range.Characters(1).Start, rngCharcs.Paragraphs(1).Range.Characters(10).End).Font.Bold = True
SamD
Reply With Quote
  #24  
Old 03-10-2020, 02:37 PM
Guessed's Avatar
Guessed Guessed is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA 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

Try this instead
Code:
  Dim rngFoot As Range
  Set rngFoot = wdDoc.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Range
  rngFoot.End = rngFoot.Start + 10
  rngFoot.Font.Bold = True
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #25  
Old 03-10-2020, 08:45 PM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Thanks Andrew Lockton(Guessed) for the reply

I get Error as Arguement Not Optional
rngFoot.End =

and then i used the following too
rngFoot.End(xltoRight)
Nothing worked

Also tried below but nothing worked
Code:
Dim rngFoot As Range
Set rngFoot = wdDoc.Sections(1).footers(wdHeaderFooterPrimary).Range.Paragraphs(1).Range   
With rngFoot
  .Collapse Direction:=0
  .End(xlToRight) = .Start + 10
  .Font.Bold = True
 End With
SamD
Reply With Quote
  #26  
Old 03-11-2020, 12:07 AM
Guessed's Avatar
Guessed Guessed is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA 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

Perhaps your first paragraph doesn't contain 10 characters.

Refer to Macropod's multi-stated request for you to use a template.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #27  
Old 03-11-2020, 02:42 AM
macropod's Avatar
macropod macropod is offline Create a Word Document with VBA Windows 7 64bit Create a Word Document with VBA Office 2010 32bit
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

Andrew, the OP can't use:
Dim rngFoot As Range
because everything is being done with late binding. Even with early binding, one would have to tell the code which application Range belongs to. In any event, since my code had already defined:
wdRng As Object
the OP could reuse that, as he had already been shown in posts 5 & 11.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #28  
Old 03-11-2020, 04:32 AM
SamDsouza SamDsouza is offline Create a Word Document with VBA Windows 10 Create a Word Document with VBA Office 2013
Advanced Beginner
Create a Word Document with VBA
 
Join Date: Aug 2019
Posts: 71
SamDsouza is on a distinguished road
Default

Macropd and Guessed

Thank you so much for your valuable Time inputs and suggestions.
I've resolved by not implementing anything in footernote . I just left as is the text without fromating in footernote.

although. It works well

Template would have been right Method. I agree

Guys thank you so much as i've learnt so much from this thread

Thanks
SamD
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a Word Document with VBA How do I create an index of every word in a document? jbengal Word 5 11-23-2022 02:17 PM
Create a Word Document with VBA Can I create word wizards with Word 2016 to automate document creation? OkiDoki Word 4 09-30-2016 11:41 AM
Create a Word Document with VBA Word 2010 - How to create a fillable document from a boilerplate document sheaters Word 2 05-04-2016 01:57 PM
How to create a special TOC in word document? gn4619 Word VBA 5 04-29-2015 04:25 PM
How to identify whether Word 2007 was used to create a document saved as Word 2003 noviceatwork Word 0 03-08-2012 06:40 AM

Other Forums: Access Forums

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