Solved

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

Posted on 2009-04-12
11
216 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
Comment Utility
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
Comment Utility
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
Comment Utility
Toni,

>>Should I post the document?

Sure!

Patrick
0
 

Author Comment

by:herkie94
Comment Utility
Here it is.  It also won't let me get to the footer now... this is weird.
Price-Sheet-Date-Modified.xls
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:herkie94
Comment Utility
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
Comment Utility
Patrick,

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

Expert Comment

by:Patrick Matthews
Comment Utility
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
Comment Utility
The suggestion I offered previously (http:#a24127036) answers the question.

Cheers,

Patrick
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
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 will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

744 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

15 Experts available now in Live!

Get 1:1 Help Now