+ Reply to Thread
Results 1 to 4 of 4

Thread: Find or search error

  1. #1
    Registered User
    Join Date
    02-02-2012
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2011
    Posts
    13

    Find or search error

    If I put FIND or SEARCH in my macro, I get "SUB or FUNCTION not defined"
    Bookname = ActiveWorkbook.Name
    zz = Search(".", Bookname - 1)
    Change search to Find, get the same error.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7/winXP
    Posts
    2,180

    Re: Find or search error

    SEARCH & FIND are worksheet functions, not VB functions. Check "Range.Find" in Help & "using Worksheet functions in VB"
    ---
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    02-02-2012
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2011
    Posts
    13

    Re: Find or search error

    I searched all of the help, only search and find in worksheet functions. Here is what I am trying to do. I want to get the active workbook name and call it Bookname. Then I want to delete the extension by finding the position of "." in the variable Bookname and save only the left characters to the "." less one.

    
    Sub NoExtension()
    '
    '
    'Save in xlsm format
    Bookname = ActiveWorkbook.Name
    
    'Remove extension
    Bookname = Left(Bookname, 6)
    'Really want
    'Bookname = left(Bookname, Find(".",Bookname)-1)
    
    Application.DisplayAlerts = False
      'Turn on next line to save file
      ActiveWorkbook.SaveAs Filename:=Bookname
      Application.DisplayAlerts = True
      Sheets(1).Name = Bookname
    End Sub

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    MSO2007 on WinXP/MSO2000 on Win7/winXP
    Posts
    2,180

    Re: Find or search error

    Option Explicit
    Sub NoExtension()
    'I want to get the active workbook name and call it Bookname
    'Then I want to delete the extension by finding the position of "."
    'in the variable Bookname and save only the left characters to the "." less one.
    
    
        Dim BookName As String, _
            DotPosition As Long
        
        BookName = ActiveWorkbook.Name
        DotPosition = InStr(BookName, ".")
        BookName = Mid(BookName, 1, DotPosition - 1)
    
        'Save in xlsm format
        
        Application.DisplayAlerts = False
        'Turn on next line to save file
        ActiveWorkbook.SaveAs Filename:=BookName
        Application.DisplayAlerts = True
        Sheets(1).Name = BookName
    End Sub
    ---
    Ben Van Johnson

+ Reply to Thread

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.2.0