betsig250
New Member
Can someone explain why this works in 2010 but not 2007? When my user tries to either run the Insert_Picture or compile it the yellow line is at this line.
Private Sub InsertPicture(Pict As String, PictCell As Range)
The error I am getting is "Compile Error in Hidden Module - Code" (name of my module)
The original line of code that my user used was the following
ActiveSheet.Pictures.Insert(Pict).Select
I modified it to the below so the picture is now an object and therefore I have the ability to resize the picture to the cells dimensions.
Thanks!
Private Sub InsertPicture(Pict As String, PictCell As Range)
The error I am getting is "Compile Error in Hidden Module - Code" (name of my module)
The original line of code that my user used was the following
ActiveSheet.Pictures.Insert(Pict).Select
I modified it to the below so the picture is now an object and therefore I have the ability to resize the picture to the cells dimensions.
Thanks!
Code:
Private Sub Insert_Picture()
Dim Pict As String
Dim ImgFileFormat As String
Dim PictCell As Range
Dim Ans As Integer
Call Unprotect
'First file format listed is the default.
ImgFileFormat = "jpg (*.jpg),*.jpg, bmp (*.bmp),others, tif (*.tif),*.tif, pdf (*.pdf), *.pdf"
Pict = Application.GetOpenFilename(ImgFileFormat)
'If user clicks cancel on the insert image box.
: GetPict
If Pict = "" Then ActiveSheet.Protect Password:="M-CS-2014"
Ans = MsgBox("Open : " & Pict, vbYesNo, "Insert Picture")
If Ans = vbNo Then GoTo GetPict
'Grabbing the cell that has the name range "Picture
GetCell:
Application.GoTo Reference:="Picture"
Set PictCell = Range(ActiveCell.Address)
'Calling the routine to insert the picture.
InsertPicture Pict, PictCell
Call Protect
End Sub
Private Sub InsertPicture(Pict As String, PictCell As Range)
Dim p As Object
Dim t, l, w, h As Double
'Inserting the picture in full resolution. Grabbing the dimmension of the picture and then resizing it in a locked ratio.
'This will fill the cell as much as it can but keep it from distorting.
Set p = ActiveSheet.Pictures.Insert(Pict)
With PictCell
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub