I have this macro which works great for getting a picture and auto sizing it to its assigned area, I tried to add my part that gets just the file name without the extension but it keeps telling me "Invalid procedure call or argument" can someone please take a look at it and see what I'm doing wrong. The part I'm trying to use is at the bottom of code starting with
yourfile. Its probably something small thats killing me...lol
Sub NewInsertMacro()
Dim myPictureName As Variant
Dim myPict As Picture
Dim myRng As Range
Dim myCurFolder As String
Dim myNewFolder As String
myCurFolder = CurDir
myNewFolder = "yourfoldernamehere"
UnProtectSheet
YesNo = MsgBox("Do you want to delete the existing pic?", vbYesNo + vbCritical, "Hello")
Select Case YesNo
Case vbYes
ActiveSheet.Pictures.Delete
Case vbNo
MsgBox "The next picture you select will overlap the existing pic"
End Select
On Error Resume Next
ChDirNet myNewFolder
If Err.Number <> 0 Then
'what should happen
MsgBox "Please change to your own folder"
Err.Clear
End If
On Error GoTo 0
myPictureName = Application.GetOpenFilename _
(filefilter:="PictureFiles,*.jpg;*.bmp;*.tif;*.gif")
ChDirNet myCurFolder
If myPictureName = False Then
Exit Sub 'user hit cancel
End If
Range("A1:G15").Select
Set myRng = Selection.Areas(1)
Set myPict = myRng.Parent.Pictures.Insert(myPictureName)
myPict.Top = myRng.Top
myPict.Width = myRng.Width
myPict.Height = myRng.Height
myPict.Left = myRng.Left
myPict.Placement = xlMoveAndSize
yourfile = Mid(yourfile, InStrRev(yourfile, "\") + 1)
yourfile = Left(yourfile, InStrRev(yourfile, ".") - 1)
Range("U12").Value = yourfile
ProtectSheet
End Sub
Bookmarks