Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-06-2023, 10:19 AM
sessilelessile sessilelessile is offline Need a macro that can shift an image and format it Windows 10 Need a macro that can shift an image and format it Office 2016
Novice
Need a macro that can shift an image and format it
 
Join Date: Jan 2023
Posts: 3
sessilelessile is on a distinguished road
Exclamation Need a macro that can shift an image and format it

Hi



I am new to VBA and macros, so any help would be greatly appreciated!

I am using a premade word template that my database fills when I pull information.
It is a label template.

I am trying to make a macro to shift one element on this label because I am unable to reformat the template.

When the database fills in the template it autogenerates a QR code (picture).

I need to shift the QR code -6 increments to the left, and also format it so it sits behind the other text on the label. The behind function is important because the QR has a white background that overlaps with the text on the label. Alternatively I would consider cropping the QR code.

I have tried writing my own macro and I was able to convert the image from inline to floating, have also been able to shift the image the -6 to the left.

However when I change the wrap formatting to behind. things go awry. The first page of the document works well, but every page after that only 1 QR code is left visible on the page, and the rest have somehow disappeared.

Any help would be great thank you!

Here is my current VBA code

Code:
Sub QR_Shift()
'
' QR_Shift Macro
'
With ActiveDocument
    For i = .InlineShapes.Count To 1 Step -1
    With .InlineShapes(i)
        If .Type = wdInlineShapePicture Then
        .ConvertToShape
        End If
    End With
Next
    For i = 1 To .Shapes.Count
        With .Shapes(i)
            If .Type = msoPicture Then
            .WrapFormat.Type = wdWrapBehind
            End If
        End With
Next
    For Each shap In ActiveDocument.Shapes
        shap.Select
        With .Shapes
            Selection.ShapeRange.IncrementLeft -6
        End With
Next
End With
End Sub

Last edited by macropod; 01-06-2023 at 05:26 PM. Reason: Added code tags
Reply With Quote
  #2  
Old 01-06-2023, 05:28 PM
macropod's Avatar
macropod macropod is offline Need a macro that can shift an image and format it Windows 10 Need a macro that can shift an image and format it Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

The required approach depends on whether the QR code is inserted in-line or floating. In any event, the solution might require nothing more complicated than making the QR code image slightly smaller.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 01-09-2023, 09:13 AM
sessilelessile sessilelessile is offline Need a macro that can shift an image and format it Windows 10 Need a macro that can shift an image and format it Office 2016
Novice
Need a macro that can shift an image and format it
 
Join Date: Jan 2023
Posts: 3
sessilelessile is on a distinguished road
Default

I wish I could simply resize the QR code but it is already being generated at the smallest useable size.

Thank you though
Reply With Quote
  #4  
Old 01-09-2023, 01:47 PM
macropod's Avatar
macropod macropod is offline Need a macro that can shift an image and format it Windows 10 Need a macro that can shift an image and format it Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

I believe you'll find the white space around the QR code is part of the QR code specification. That may be a fixed amount of white space or a white space proportional to the size of the QR code itself. Its reduction or removal (including by repositioning within the label) is liable to compromise the integrity of any QR code scanning. Placing the code behind the text will cause the text to intrude on that white space and potentially to obscure parts of the QR code itself.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 01-09-2023, 01:57 PM
sessilelessile sessilelessile is offline Need a macro that can shift an image and format it Windows 10 Need a macro that can shift an image and format it Office 2016
Novice
Need a macro that can shift an image and format it
 
Join Date: Jan 2023
Posts: 3
sessilelessile is on a distinguished road
Default

Thank you for the lesson on how QR codes work!

Thankfully the way the label template is set up there will always be room for the QR to have 'white space' around it (it gets printed on black metal so it's inverted), however the border is unnecessarily large.

With the QR code being manually manipulated to be "behind text" (picture formatting not literally behind text) and shifted to the left, it still functions. I just need a macro to repeat this process.

Best.
Reply With Quote
  #6  
Old 01-09-2023, 02:06 PM
macropod's Avatar
macropod macropod is offline Need a macro that can shift an image and format it Windows 10 Need a macro that can shift an image and format it Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
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

Quote:
Originally Posted by sessilelessile View Post
Thankfully the way the label template is set up there will always be room for the QR to have 'white space' around it (it gets printed on black metal so it's inverted), however the border is unnecessarily large.
In that case, simply changing the table cell border size may be all you need. That should be done once - in the mailmerge main document - before the merge is executed.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Tags
image, macro, picutre



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a macro that can shift an image and format it How can I create a macro to shift the content of all subsequent footnotes up one position? Atfon Word VBA 4 03-29-2016 05:51 AM
Need a macro that can shift an image and format it Shift Excel Cell after executing a macro for second time LearningMacro Excel Programming 2 01-08-2015 03:05 PM
Need a macro that can shift an image and format it 1.image in a table 2.right click 3.menu click format 4.a format column appears OldFatDog Drawing and Graphics 1 06-13-2014 11:19 PM
Need a macro that can shift an image and format it Noob here - I need a shift calendar by days with count of shift. freeman Excel 8 09-12-2012 08:45 AM
Need a macro that can shift an image and format it Vector image format jespestana Drawing and Graphics 4 11-26-2010 03:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:50 PM.


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