Results 1 to 7 of 7

Delete code when saving the file

Threaded View

  1. #1
    Forum Contributor Bob@Sun's Avatar
    Join Date
    09-03-2009
    Location
    Montuak, Usa
    MS-Off Ver
    Excel 2007
    Posts
    438

    Delete code when saving the file

    Hello again,

    I have posted already the problem to delete the code when sending a sheet via email and I have found the solution to the problem.

    I tried to do the same when saving the file to specific folder, but i am facing problem.
    The code that I am using now is:

    Sub SaveFile()
    
    Dim CurrentPath As String
    Const PathToSaveTo As String = "C:\Documents and Settings\All Users\Documents\"
        'Store the current path
        CurrentPath = CurDir
        ''Change the path to the one we want
        'ChDrive "C"
        'ChDir PathToSaveTo
        ''or perhaps...
        SetCurrentDirectory PathToSaveTo    '"\\SomeServer\Some Path"
        'test to see if the folder is already saved in the correct folder
        
                 With ThisWorkbook
                If .Path <> PathToSaveTo Then
                .SaveAs FileName:=PathToSaveTo & .Name
                         Else
                'file is already saved in folder therefore just save it
                .Save
                
            End If
        End With
        ''Change the path back
        'ChDrive CurrentPath
        SetCurrentDirectory CurrentPath
        
    End Sub
    Can I add somewhere in this code the lines that will delete the code form the file?

      Destwb.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule.DeleteLines 1, _
      Destwb.VBProject.VBComponents(ActiveSheet.CodeName).CodeModule.CountOfLines
    Last edited by Bob@Sun; 01-26-2010 at 04:43 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