+ Reply to Thread
Results 1 to 7 of 7

VBA not saving template

Hybrid View

mickyh VBA not saving template 12-25-2014, 01:36 PM
xladept Re: VBA not saving template 12-25-2014, 03:52 PM
mickyh Re: VBA not saving template 12-25-2014, 08:04 PM
xladept Re: VBA not saving template 12-25-2014, 09:07 PM
mickyh Re: VBA not saving template 12-27-2014, 01:26 PM
mickyh Re: VBA not saving template 01-08-2015, 06:38 PM
xladept Re: VBA not saving template 01-08-2015, 07:44 PM
  1. #1
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    VBA not saving template

    Hello and merry Christmas.

    I have a template which with a lot of help on from members which saves a spreadsheet with the next sequential number (by adding a number to the relevant square in the template file). This worked great until I made some changes to it! Everything still works as I need it to except it doesn't seem to update the template number therefore every time I run the template it gives the next file the same number. I cannot figure out why this so any help would be gratfully accepted!

    Regards

    Mick


    Sub ReNameFile()
    
    
    Const wsINV As String = "Imput Sheet"
    Dim newFile As String, fName As String
    Dim wbook As Workbook
    Dim Today As Date
    Dim NewVal As Long
    Dim Template As String
    Dim dt As String, wbNam As String, FileName As String
        
        
        With ActiveWorkbook
            If Range("AA1") = "" Then      'the doublecheck cell
                Application.ScreenUpdating = False
                Application.EnableEvents = False
                Application.DisplayAlerts = False
                Template = "C:\Users\Mick\Documents\Custom Office Templates\New Estimate Template.xltm" 'reopen the template
                
                Workbooks.Open Template
                    With ActiveWorkbook.Sheets(wsINV)    'update the template's current inv number
                        .Range("J2").Value = .Range("J2").Value + 1
                    NewVal = .Range("J2").Value + 1       'remember the new number
            
                     ActiveWorkbook.Save  'close the template, save changes
                    Application.ScreenUpdating = True
                    Application.EnableEvents = True
                 End With
          
        
            
            
           
           
            End If
         
         
            With Sheets("Imput Sheet")
             
            Range("J2").Value = NewVal             'put new number into current workbook
            Range("AA1") = "Incremented"           'flag the doublecheck cell
             
         
            If .Range("C3") = "" Then _
            .Range("C3").Value = InputBox("Please enter a client name")
       
            If .Range("J4") = "" Then _
            .Range("J4").Value = Date
        
            End With
            
       
            wbNam = Range("A24")
            dt = Format(CStr(Now), "dd_mm_yy")
            ChDir _
                "C:\Users\Mick\Dropbox\SPSL Shared\Estimates 2014\"
            ActiveWorkbook.SaveAs FileName:=wbNam & " " & dt, FileFormat:=(52)
          End With
          End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA not saving template

    Maybe:

     'If .Range("J4") = "" Then _
            .Range("J4").Value = Date
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: VBA not saving template

    Thanks for the reply: The problem I'm having is with the template. it should (and used to) increase the number by 1 in J2 each time the macro was run and save the new number. (so that when the macro was used next it gave the next sequential No) everything works as I need it to apart from the no in J2 in the template being incremented.

     Workbooks.Open Template
                    With ActiveWorkbook.Sheets(wsINV)    'update the template's current inv number
                        .Range("J2").Value = .Range("J2").Value + 1
                    NewVal = .Range("J2").Value + 1       'remember the new number
            
                     ActiveWorkbook.Save  'close the template, save changes
                    Application.ScreenUpdating = True
                    Application.EnableEvents = True
                 End With

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA not saving template

    Hi micky,

    Is your Template really a template extension .xltx??

  5. #5
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: VBA not saving template

    Hi xladept
    My template is a macro enabled template .xltm. again it all appears to work except that it wont save the updated no on the template. it might be that activeworkbook reference that's wrong? unfortunately I don't understand enough about vba to solve it!

    Thanks for getting back to me.

  6. #6
    Registered User
    Join Date
    03-31-2011
    Location
    Swindon, England
    MS-Off Ver
    Excel 2016
    Posts
    31

    Re: VBA not saving template

    I Found the error it needed to have ,editable = true after the path to open the template!

    Sub ReNameFile()
    
    
    Const wsINV As String = "Imput Sheet"
    Dim newFile As String, fName As String
    Dim wbook As Workbook
    'Dim ClientName As String
    Dim Today As Date
    'Dim strFilename As String
    'Dim strFolder As String
    Dim NewVal As Long
    Dim Template As String
    
    Dim dt As String, wbNam As String, FileName As String
        
        
        With Sheets(wsINV)
            If Range("AA1") = "" Then      'the doublecheck cell
                Application.ScreenUpdating = False
                Application.EnableEvents = False
                Application.DisplayAlerts = False
                'Template = "C:\Users\Mick\Documents\Custom Office Templates\New Estimate Template.xltm" 'reopen the template
                
                Workbooks.Open FileName:="C:\Users\Mick\Documents\Custom Office Templates\New Estimate Template.xltm", Editable:=True
               'Activate Workbook
    'Workbooks.Activate Template
    
                   
                    With ActiveWorkbook.Sheets(wsINV)    'update the template's current inv number
                        .Range("J2").Value = .Range("J2").Value + 1
                    NewVal = .Range("J2").Value       'remember the new number
                    End With
            ActiveWorkbook.Close True
    
                   'ActiveWorkbook.Close False 'close the template, save changes
                    Application.ScreenUpdating = True
                    Application.EnableEvents = True
           
            End If
            
            End With
            
           
            With Sheets("Imput Sheet")
             
            Range("J2").Value = NewVal             'put new number into current workbook
            Range("AA1") = "Incremented"           'flag the doublecheck cell
             
         
            If .Range("C3") = "" Then _
            .Range("C3").Value = InputBox("Please enter a client name")
       
            If .Range("J4") = "" Then _
            .Range("J4").Value = Date
        
            End With
            
       
            wbNam = Range("A24")
            dt = Format(CStr(Now), "dd_mm_yy")
            ChDir _
                "C:\Users\Mick\Dropbox\SPSL Shared\Estimates 2015\"
            ActiveWorkbook.SaveAs FileName:="Estimate" & " " & wbNam & " " & dt, FileFormat:=(52)
                
          
          End Sub

  7. #7
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: VBA not saving template

    Good to know! Glad you got it

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. CSV file created from template is not saving to same location as the template.
    By SGALLAG1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2012, 11:26 AM
  2. Replies: 0
    Last Post: 02-28-2012, 11:40 AM
  3. Saving:template file
    By burgerboy2k6 in forum Excel General
    Replies: 0
    Last Post: 03-03-2007, 09:18 PM
  4. [SOLVED] saving template
    By Marlis in forum Excel General
    Replies: 3
    Last Post: 09-10-2005, 08:07 PM
  5. Saving CSV to a template
    By Josh O. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 08:06 PM

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