VB Code to insert pdf file and fix in cells (cross post)

ateebali

Board Regular
Joined
Dec 13, 2018
Messages
108
https://chandoo.org/forum/threads/vb-code-to-insert-pdf-image.42675/

This is cross post, was not getting reply so posting here.

[FONT=&quot]I am using following code and it is importing jpeg image in cell range B14 : P[/FONT][FONT=&quot]28 (Merge cells)
[/FONT]

[FONT=&quot]I need vb code which can insert pdf file as image in the same merge range, the picture should be fixed in range, thanks

Code:
[/FONT][/COLOR][COLOR=#141414][FONT=inherit]Sub GetPic()[/FONT][/COLOR]
<code style="box-sizing: border-box; font-family: inherit; font-size: 1em;">

Dim fNameAndPath As Variant
Dim pRng As Range
Dim pTop As Long, pLeft As Long, pHeight As Long, pWidth As Long

fNameAndPath = Application.GetOpenFilename(Title:="Select Picture To Be Imported")
If fNameAndPath = False Then Exit Sub

Set pRng = ActiveSheet.Range("C15")

With pRng.MergeArea
    pTop = .Top
    pLeft = .Left
    pHeight = .Height
    pWidth = .Width
End With

ActiveSheet.Pictures.Insert(fNameAndPath).Select

With Selection.ShapeRange
    .LockAspectRatio = msoFalse
    .Left = pLeft
    .Top = pTop
    .Width = pWidth
    .Height = pHeight
End With

With Selection
    .Placement = xlMoveAndSize
    .PrintObject = True
End With

 </code>[COLOR=#141414][FONT=inherit]End Sub[/FONT][/COLOR][COLOR=#141414][FONT=&quot]
[/FONT]
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Code:
Range("B14:P28").Select    ActiveSheet.OLEObjects.Add(ClassType:="AcroExch.Document.7", Link:=False, _
        DisplayAsIcon:=False).Activate

this code working fine, but it is not adjusting image into required merge cell, please need help
 
Upvote 0

Forum statistics

Threads
1,214,560
Messages
6,120,217
Members
448,951
Latest member
jennlynn

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top