Results 1 to 3 of 3

file name in macro not working

Threaded View

  1. #1
    Forum Contributor
    Join Date
    05-13-2006
    Location
    League City, TX
    MS-Off Ver
    2010
    Posts
    139

    file name in macro not working

    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
    Last edited by mrggutz; 09-13-2010 at 07:22 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1