Solved

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

Posted on 2009-04-12
11
217 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
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.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

914 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now