Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-04-12
11
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
11 Comments
 
LVL 93

Accepted Solution

by:
Patrick Matthews earned 2000 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 93

Expert Comment

by:Patrick Matthews
ID: 24127375
Toni,

>>Should I post the document?

Sure!

Patrick
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 93

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 93

Expert Comment

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

Cheers,

Patrick
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

721 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