Insert a PDF file into a cell
soso69960
Posted messages
2
Status
Member
-
soso69960 Posted messages 2 Status Member -
soso69960 Posted messages 2 Status Member -
Hello,
I would like to know if it would be possible to insert a PDF into a predefined cell (one we would have chosen) using a macro?
I can insert a PDF but only into the active cell. Here is my code:
Sub insertpdf()
fileToOpen = Application.GetOpenFilename("pdf Files (*.pdf), *.pdf")
If fileToOpen <> False Then
ActiveSheet.OLEObjects.Add(Filename:= fileToOpen, Link:=False, DisplayAsIcon:=False).Select
Selection.ShapeRange.ScaleWidth 0.54, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.4, msoFalse, msoScaleFromTopLeft
Else
MsgBox "pas de fichier selectionné"
End If
End Sub
Being new to VBA, I am asking for your help.
Configuration: Windows / Chrome 38.0.2125.104
I would like to know if it would be possible to insert a PDF into a predefined cell (one we would have chosen) using a macro?
I can insert a PDF but only into the active cell. Here is my code:
Sub insertpdf()
fileToOpen = Application.GetOpenFilename("pdf Files (*.pdf), *.pdf")
If fileToOpen <> False Then
ActiveSheet.OLEObjects.Add(Filename:= fileToOpen, Link:=False, DisplayAsIcon:=False).Select
Selection.ShapeRange.ScaleWidth 0.54, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight 0.4, msoFalse, msoScaleFromTopLeft
Else
MsgBox "pas de fichier selectionné"
End If
End Sub
Being new to VBA, I am asking for your help.
Configuration: Windows / Chrome 38.0.2125.104
2 answers
-
Salam soso69960.
I think that to position your object on cell D5, for example, you should add this code:
With Selection
.Top = Range("D5").Top
.Left = Range("D5").Left
.Height = Range("D5").Height
.Width = Range("D5").Width
End With
To try! :)
--
"Repousse le mal par le bien; et voilà que celui avec qui tu avais une animosité devient tel un ami chaleureux" (Coran)
"Celui qui ne sait pas partager est infirme de ses émotions". (Marc Levy) -
So, I found the solution, here is the code that works:
Sub CommandButton2_Click()
fileToOpen = Application.GetOpenFilename("pdf Files (*.pdf), *.pdf")
If fileToOpen <> False Then
Range("B369").Select
ActiveSheet.OLEObjects.Add(Filename:=fileToOpen, Link:=False, DisplayAsIcon:=False).Select
Else
MsgBox "no file selected"
End If
End Sub
And thanks a lot for your time redaiwa.