Further to JBeaucaire's comment, specific formatting requirements could be incorporated into my code (and no doubt JB's solution) but you would need to specify them!
Further to JBeaucaire's comment, specific formatting requirements could be incorporated into my code (and no doubt JB's solution) but you would need to specify them!
Hi thanks for you replies. The code works fine on its own when the sheets are created but when I try to attach it to a user form that I use to open, format and save the spread sheet it does not work.
Error message :- run time error 9 : subscript out of range.
It only seems to work when I save, close and then re-open and run the code separately. When the code is run, the dates change to mm/dd/yyyy, but even when I go to format cell it stays as it is.
The Call Addsheets to print formats the sheets for printing and Call x copies the rows into the corresponding sheets.![]()
Private Sub cbReport_Click() Private Sub cbReport_Click() Dim day As String Dim month As String Dim year As String Dim month_name As String Dim year_long As String Dim storage_path As String Dim generic_file_name As String Dim file_name As String Dim report_length As Integer Dim line_number As Integer 'Assign text box values to respective variables day = tbDay month = tbMonth year = tbYear 'Close Report window and set text box values to null Report.Hide tbDay = "" tbMonth = "" tbYear = "" 'Set path for report storage area storage_path = Range("Path!A1") 'Determine generic file name generic_file_name = Range("Path!A2") 'Determine report file name from day, month and year 'Determine month name Select Case month Case "01" month_name = "January" Case "02" month_name = "February" Case "03" month_name = "March" Case "04" month_name = "April" Case "05" month_name = "May" Case "06" month_name = "June" Case "07" month_name = "July" Case "08" month_name = "August" Case "09" month_name = "September" Case "10" month_name = "October" Case "11" month_name = "November" Case "12" month_name = "December" End Select 'Determine year in 4 digit format year_long = "20" & year & "" 'Store file name in variable file_name file_name = "" & generic_file_name & " " & day & " " & month & " " & year & ".xls" 'Open report file Workbooks.Open Filename:="" & storage_path & "\" & year_long & "\" & month_name & "\" & file_name & "" 'Procedure to format report with: Call AddsheetstoPrint Call x exit_point: 'Save report file ActiveWorkbook.Save 'Close report file ActiveWorkbook.Close 'Return to Main worksheet on macro program file Sheets("Main").Select 'Display confirmation message box MsgBox "Report completed, stored in file:" & Chr(13) & storage_path & "\" & year_long & "\" & month_name & "\" & file_name & "", , "" End Sub End Sub
Last edited by Hblbs; 03-06-2009 at 05:08 AM.
Bump to see if anyone can help with this.
Many thanks
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks