Home > Software engineering >  VB to create excel pictures stored by link is modified to insert
VB to create excel pictures stored by link is modified to insert

Time:11-16

My VB code inserted in office2010 become links pictures, who can help the younger brother to modify the following code, thank you,

Public Sub addPicture (ByVal strFileName As String, _
ByVal lngLeft As Long, ByVal lnTop As Long, _
ByVal lngWidth As Long, ByVal lngHeight As Long)

'Call XLsheet. Shapes. AddPicture (strFileName, False, True, lngLeft, lnTop, lngWidth, lngHeight)

End Sub

Public Sub InsertPicture (ByVal strFilePathName As String, _
ByVal strPosition As String, _
ByVal dblImageWidth As a Decimal)
XLsheet. Range (strPosition). The Select ()


XLsheet. Pictures. Insert (strFilePathName). The Select ()
'Selection. ShapeRange. LockAspectRatio=True
'Selection. ShapeRange. Width=dblImageWidth
End Sub

Public Sub InsertCellPicture (ByVal row As an Integer, ByVal col As an Integer, ByVal strFilePathName As String)
XLsheet. Cells (the row, col). The Select ()
XLsheet. Pictures. Insert (strFilePathName). The Select ()
'Selection. ShapeRange. LockAspectRatio=True
'Selection. ShapeRange. Width=dblImageWidth
End Sub

CodePudding user response:

 
Sub macro (1)
'

'to the current sheet insert picture
AddPicture ActiveSheet. "B: \ ab. JPG", 100, 100, 250, 125
To the designated sheet insert picture
'AddPicture Sheets (" Sheet1 "), "B: \ ab. JPG", 100, 100, 250, 125

End Sub
Public Sub addPicture (XLSheet As Object, ByVal strFileName As String, _
ByVal lngLeft As Long, ByVal lnTop As Long, _
ByVal lngWidth As Long, ByVal lngHeight As Long)

Dim objRange
The Set objRange=XLSheet. Pictures. Insert (strFileName)
ObjRange. ShapeRange. Left=lngLeft
ObjRange. ShapeRange. Top=lnTop
ObjRange. ShapeRange. Width=lngWidth
ObjRange. ShapeRange. Height=lngHeight
End Sub

CodePudding user response:

 
Sub macro (1)
'

'position to the specified range of the specified sheet insert pictures, and drawing pictures to adapt to the range
Dim objDesRange As Range

Set objDesRange=Sheets (" Sheet1 "). The Range (" B2: C4 ")
AddPicture Sheets (" Sheet1 "), "B: \ ab. JPG", objDesRange. Left, objDesRange. Top, objDesRange. Width, objDesRange. Height, True

End Sub
Public Sub addPicture (XLSheet As Object, ByVal strFileName As String, _
ByVal lngLeft As Long, ByVal lnTop As Long, _
ByVal lngWidth As Long, ByVal lngHeight As Long, _
ByVal blnIsScale As Boolean)

Dim objRange
The Set objRange=XLSheet. Pictures. Insert (strFileName)
If blnIsScale Then 'tensile
ObjRange. ShapeRange. LockAspectRatio=msoFalse
The Else 'to maintain the original proportion
ObjRange. ShapeRange. LockAspectRatio=msoTrue
End the If
ObjRange. ShapeRange. Left=lngLeft
ObjRange. ShapeRange. Top=lnTop
ObjRange. ShapeRange. Width=lngWidth
ObjRange. ShapeRange. Height=lngHeight
End Sub


To improve it and add parameters to determine if not lock aspect ratio stretching,
And the call in the sample range to determine the size and location of the image,

CodePudding user response:

And I can't change the image path later will not be able to show! To solve!
  • Related