Solved

Can somebody help me with fixing my date modified code in VBA?

Posted on 2009-04-12
11
219 Views
Last Modified: 2012-06-21
I have added a date modified code that was recommended by someone else in a forum somewhere.  It works... however now the month (mm) is missing, and when i formulated the font size, it shows up at 409pts??  Does anyone have an idea of what I might be doing wrong?
Code is shown below.

Or... is there a better way to do this?  My customer wants the date the file was modified to show up on the top of the sheet, in the header.  And it should only show the date that it was modified, not the current date that you open the file.

Thanks,
Toni
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    For Each ws In ActiveWorkbook.Worksheets
       ws.PageSetup.RightHeader = "&""Arial""&I&7" & Format(Now, "mm/dd/yy")
    Next
End Sub

Open in new window

0
Comment
Question by:herkie94
  • 4
  • 4
11 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 24127036
Hello herkie94,

I think you left out a space.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    For Each ws In ActiveWorkbook.Worksheets
       ws.PageSetup.RightHeader = "&""Arial,Italic""&7 " & Format(Now, "mm/dd/yyyy")
    Next
End Sub

Regards,

Patrick
0
 

Author Comment

by:herkie94
ID: 24127303
Patrick,

Where do you see the extra space?  I made the adjustments similar to yours, but did not see an extra space.

Should I post the document?

Thanks,
Toni
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24127375
Toni,

>>Should I post the document?

Sure!

Patrick
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:herkie94
ID: 24127682
Here it is.  It also won't let me get to the footer now... this is weird.
Price-Sheet-Date-Modified.xls
0
 

Author Comment

by:herkie94
ID: 24127690
Another issue that came up after doing all of this... I can't access my header/footer anymore by going into a separate window.  Now Excel is showing it on the page rather than separately.  Is there something that I accidentally hit to make it do that? I want it to go back.
0
 

Author Comment

by:herkie94
ID: 24211268
Patrick,

Were you able to take a look at the file I uploaded?
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 25848325
herkie94,

My apologies for the lack of response.

Look at these two lines...

From your code:
       ws.PageSetup.RightHeader = "&""Arial""&I&7" & Format(Now, "mm/dd/yy")

from mine:
       ws.PageSetup.RightHeader = "&""Arial,Italic""&7 " & Format(Now, "mm/dd/yyyy")

Note how mine has a space following the 7, and yours does not.  When I make that correction in the code, it runs
just fine, as I indicated previously.  I just tested this against your sample file.

Patrick

Patrick
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 25848335
The suggestion I offered previously (http:#a24127036) answers the question.

Cheers,

Patrick
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question