Format problem

G

Guest

When I try to save the file it fails because DateSave is formated 5/1/07
even thou E213 is formated 5-1-07

Is there any way to force the DateSave to 5-1-07 and also can the existing
code be simplified J

Private Sub CommandButton4_Click() 'Saves wookbook and exits

Dim NameSave As Range
Dim DateSave As Range

Sheets("Checkbook").Select

Set NameSave = Worksheets("Summary").Range("A2")
Set DateSave = Worksheets("Summaryk").Range("E213")

Workbooks.Add
ActiveWorkbook.SaveAs Filename:="TempData.xls"

Windows("Bank Records.XLS").Activate

Application.GoTo Reference:="Database"
Selection.Copy

Windows("TempData.XLS").Activate
Range("A1").Select
ActiveSheet.Paste

BankRecords = InputBox("Please enter file name to save", "Bank Records
Backup", "C:\Bank Records\" & NameSave & "" & DateSave)
ActiveWorkbook.SaveAs Filename:=BankRecords + "xls"
ActiveWorkbook.Close

oldjay
 
R

Ron Rosenfeld

When I try to save the file it fails because DateSave is formated 5/1/07
even thou E213 is formated 5-1-07

Is there any way to force the DateSave to 5-1-07 and also can the existing
code be simplified J

Private Sub CommandButton4_Click() 'Saves wookbook and exits

Dim NameSave As Range
Dim DateSave As Range

Sheets("Checkbook").Select

Set NameSave = Worksheets("Summary").Range("A2")
Set DateSave = Worksheets("Summaryk").Range("E213")

Workbooks.Add
ActiveWorkbook.SaveAs Filename:="TempData.xls"

Windows("Bank Records.XLS").Activate

Application.GoTo Reference:="Database"
Selection.Copy

Windows("TempData.XLS").Activate
Range("A1").Select
ActiveSheet.Paste

BankRecords = InputBox("Please enter file name to save", "Bank Records
Backup", "C:\Bank Records\" & NameSave & "" & DateSave)
ActiveWorkbook.SaveAs Filename:=BankRecords + "xls"
ActiveWorkbook.Close

oldjay

Try this:

....& NameSave & "" & DateSave.Text)


If that doesn't work, you can use the Format function to ensure DateSave is in
the format you want in the file name.
--ron
 
G

Guest

When I run macro it fails at
Set DateSave = Format(Range("E213"), "[$-409]mm-dd-yy;@")

Runtime error 424
Object required

Mike said:
Set DateSave = Format(Range("E213"), "[$-409]mm-dd-yy;@")

Oldjay said:
When I try to save the file it fails because DateSave is formated 5/1/07
even thou E213 is formated 5-1-07

Is there any way to force the DateSave to 5-1-07 and also can the existing
code be simplified J

Private Sub CommandButton4_Click() 'Saves wookbook and exits

Dim NameSave As Range
Dim DateSave As Range

Sheets("Checkbook").Select

Set NameSave = Worksheets("Summary").Range("A2")
Set DateSave = Worksheets("Summaryk").Range("E213")

Workbooks.Add
ActiveWorkbook.SaveAs Filename:="TempData.xls"

Windows("Bank Records.XLS").Activate

Application.GoTo Reference:="Database"
Selection.Copy

Windows("TempData.XLS").Activate
Range("A1").Select
ActiveSheet.Paste

BankRecords = InputBox("Please enter file name to save", "Bank Records
Backup", "C:\Bank Records\" & NameSave & "" & DateSave)
ActiveWorkbook.SaveAs Filename:=BankRecords + "xls"
ActiveWorkbook.Close

oldjay
 
G

Guest

& NameSave & "" & DateSave.Text) didn't work 9same result)
Tried
Set DateSave = Format(Range("E213"), "[$-409]mm-dd-yy;@") per Mikes reply
It returned Object required
 
R

Ron Rosenfeld

& NameSave & "" & DateSave.Text) didn't work 9same result)
Tried
Set DateSave = Format(Range("E213"), "[$-409]mm-dd-yy;@") per Mikes reply
It returned Object required

I would expect that.

Did you try my alternate solution. Spelled out, it would give you:

BankRecords = InputBox("Please enter file name to save", "Bank Records
Backup", "C:\Bank Records\" & NameSave & "" & Format(DateSave,"m-d-yyyy")


It would be more robust than using DateSave.text as it would be independent of
the formatting in the cell.

I'm surprised that using DateSave.Text didn't work, though.

Note the following that shows how this works:

==============================
Sub foo()
Dim DateSave As Range
Set DateSave = [a1]

Debug.Print "With Format Command:",, Format(DateSave, "m-d-yyyy")
Debug.Print "from Cell formatted as " & DateSave.NumberFormat, DateSave.Text

End Sub
----------------------------

Immediate Window:

With Format Command: 1-2-2007
from Cell formatted as m-d-yyyy 1-2-2007

=====================================================


--ron
 
G

Guest

I copied your code over my code and got a compile error - Expected: list
separator or)

Ron Rosenfeld said:
& NameSave & "" & DateSave.Text) didn't work 9same result)
Tried
Set DateSave = Format(Range("E213"), "[$-409]mm-dd-yy;@") per Mikes reply
It returned Object required

I would expect that.

Did you try my alternate solution. Spelled out, it would give you:

BankRecords = InputBox("Please enter file name to save", "Bank Records
Backup", "C:\Bank Records\" & NameSave & "" & Format(DateSave,"m-d-yyyy")


It would be more robust than using DateSave.text as it would be independent of
the formatting in the cell.

I'm surprised that using DateSave.Text didn't work, though.

Note the following that shows how this works:

==============================
Sub foo()
Dim DateSave As Range
Set DateSave = [a1]

Debug.Print "With Format Command:",, Format(DateSave, "m-d-yyyy")
Debug.Print "from Cell formatted as " & DateSave.NumberFormat, DateSave.Text

End Sub
----------------------------

Immediate Window:

With Format Command: 1-2-2007
from Cell formatted as m-d-yyyy 1-2-2007

=====================================================


--ron
 
R

Ron Rosenfeld

I copied your code over my code and got a compile error - Expected: list
separator or)

You don't supply enough information for me to be sure what the problem is. I
suspect that in pasting the code, you may not be taking the line breaks induced
by the newsgroup and/or your reader into account. My code was not designed to
be just copied over your code.
--ron
 
G

Guest

I put in the missing ")" and it worked
Thanks

Oldjay said:
I copied your code over my code and got a compile error - Expected: list
separator or)

Ron Rosenfeld said:
& NameSave & "" & DateSave.Text) didn't work 9same result)
Tried
Set DateSave = Format(Range("E213"), "[$-409]mm-dd-yy;@") per Mikes reply
It returned Object required

I would expect that.

Did you try my alternate solution. Spelled out, it would give you:

BankRecords = InputBox("Please enter file name to save", "Bank Records
Backup", "C:\Bank Records\" & NameSave & "" & Format(DateSave,"m-d-yyyy")


It would be more robust than using DateSave.text as it would be independent of
the formatting in the cell.

I'm surprised that using DateSave.Text didn't work, though.

Note the following that shows how this works:

==============================
Sub foo()
Dim DateSave As Range
Set DateSave = [a1]

Debug.Print "With Format Command:",, Format(DateSave, "m-d-yyyy")
Debug.Print "from Cell formatted as " & DateSave.NumberFormat, DateSave.Text

End Sub
----------------------------

Immediate Window:

With Format Command: 1-2-2007
from Cell formatted as m-d-yyyy 1-2-2007

=====================================================


--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top