For Programmers: Free Programming Magazines  


Home > Archive > Visual Basic > September 2004 > altering the modified date/time of a Word document









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author altering the modified date/time of a Word document
Bob O`Bob

2004-09-17, 8:55 pm

I've got the classic file date/timestamp editing stuff from Randy's
VBnet pages, and also some other similar code (I forget where from)
which uses CreateFileA()

Neither is able to touch an MSWord document for me.
Attempts to open one give me nothing but invalid handle values (-1)

Obviously I can alter the date on my system and save various test files
using Word, but that's now grown really *^$%#^$ing tedious!

Anyone know a way to create a similar utility that can do what it takes
to change the modification date on a *Word* document to a chosen value?



Bob
Mike D Sutton

2004-09-18, 8:55 pm

Hi Bob,

> I've got the classic file date/timestamp editing stuff from Randy's
> VBnet pages, and also some other similar code (I forget where from)
> which uses CreateFileA()
>
> Neither is able to touch an MSWord document for me.
> Attempts to open one give me nothing but invalid handle values (-1)
>
> Obviously I can alter the date on my system and save various test files
> using Word, but that's now grown really *^$%#^$ing tedious!
>
> Anyone know a way to create a similar utility that can do what it takes
> to change the modification date on a *Word* document to a chosen value?


See if this works, grab this library:
Http://www.mvps.org/EDais/Code/Libr...ity/modTime.bas
Then try this code:

'***
Dim FileTimes As typFileTimes

SET FILENAME HERE THEN KILL THIS LINE
Const FileName As String = "X:\Path\file.doc"

If (GetFileTimes(FileName, FileTimes)) Then
FileTimes.ftModified = SystemTimeToFileTime(VBTimeToSystemTime(
_
DateAdd("d", -2, SystemTimeToVBTime(FileTimeToSystemTime(
FileTimes.ftModified)))))
If (Not SetFileTimes(FileName, FileTimes)) Then Call MsgBox("Error setting file times")
Else
Call MsgBox("Error getting file times")
End If
'***

Seems to work fine here, running WinXP Pro and Word 2003.
Hope this helps,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://www.mvps.org/EDais/


Bob O`Bob

2004-09-20, 3:56 pm

Mike D Sutton wrote:
> Hi Bob,
>
>
>
>
> See if this works, grab this library:
> Http://www.mvps.org/EDais/Code/Libr...ity/modTime.bas
> Then try this code:
>
> '***
> Dim FileTimes As typFileTimes
>
> SET FILENAME HERE THEN KILL THIS LINE
> Const FileName As String = "X:\Path\file.doc"
>
> If (GetFileTimes(FileName, FileTimes)) Then
> FileTimes.ftModified = SystemTimeToFileTime(VBTimeToSystemTime(
_
> DateAdd("d", -2, SystemTimeToVBTime(FileTimeToSystemTime(
FileTimes.ftModified)))))
> If (Not SetFileTimes(FileName, FileTimes)) Then Call MsgBox("Error setting file times")
> Else
> Call MsgBox("Error getting file times")
> End If
> '***
>
> Seems to work fine here, running WinXP Pro and Word 2003.
> Hope this helps,
>
> Mike
>
>
> - Microsoft Visual Basic MVP -
> E-Mail: EDais@mvps.org
> WWW: Http://www.mvps.org/EDais/
>
>



I give up. I can't overcome all the "ambiguous name detected" errors.

Adding "API" to the declare just so you can reuse the *actual* API's
name as a VB function has to be one of the dumbest things I've ever seen
any competent coder do.
Mike D Sutton @ Work

2004-09-20, 3:56 pm

> I give up. I can't overcome all the "ambiguous name detected" errors.

Oh quit whinging and just remove the API declarations (you don't need them as they're wrapped by the class) or do a find as replace
in my code and rename them to whatever you wish if it bugs you so much.

> Adding "API" to the declare just so you can reuse the *actual* API's
> name as a VB function has to be one of the dumbest things I've ever seen
> any competent coder do.


You assume I'm a competent coder, a mistake sir, I can assure you.
You're welcome, incidentally..

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://www.mvps.org/EDais/


Bob O`Bob

2004-09-20, 3:56 pm

Mike D Sutton @ Work wrote:

>
>
> Oh quit whinging and just remove the API declarations (you don't need them as they're wrapped by the class) or do a find as replace
> in my code and rename them to whatever you wish if it bugs you so much.


"wrapped by the class"

what class would that be?

Bob O`Bob

2004-09-20, 3:56 pm

Mike D Sutton @ Work wrote:
>
> Oh quit whinging and just remove the API declarations (you don't need them as they're wrapped by the class) or do a find as replace
> in my code and rename them to whatever you wish if it bugs you so much.


You ought to try that find & replace trick sometime. Maybe then you'll
see what else it screws up. It's not like you can change the names of
the actual entry points in the compiled libraries. That's why I
consider it a gigantic mistake to try to reuse those exact names, no
matter what kinds of wrappers you may think you've applied.
Mike D Sutton

2004-09-21, 3:55 am

> You ought to try that find & replace trick sometime. Maybe then you'll
> see what else it screws up. It's not like you can change the names of
> the actual entry points in the compiled libraries. That's why I
> consider it a gigantic mistake to try to reuse those exact names, no
> matter what kinds of wrappers you may think you've applied.


Come on, I'd expect more from you.. It's really not that difficult:
"FileTimeToSystemTimeAPI" -> "AUniqueString" (3 instances)
"FileTimeToSystemTime" -> "YourNewFunctionName" (5 instances)
"AUniqueString" -> "FileTimeToSystemTime" (3 instances)
Kill the alias on the declare and you're done - It even keeps the documentation at the top consistent.
Since you're bound to whinge about having to do this yourself I've re-uploaded the library with the names changed for you (although
I doubt I'll get any thanks for it still, but ah well.)
Hope this helps someone else once it circulates round the archives a bit.

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://www.mvps.org/EDais/


Bob O`Bob

2004-09-21, 3:55 am

Mike D Sutton wrote:

>
>
> Come on, I'd expect more from you.. It's really not that difficult:
> "FileTimeToSystemTimeAPI" -> "AUniqueString" (3 instances)
> "FileTimeToSystemTime" -> "YourNewFunctionName" (5 instances)
> "AUniqueString" -> "FileTimeToSystemTime" (3 instances)
> Kill the alias on the declare and you're done - It even keeps the documentation at the top consistent.
> Since you're bound to whinge about having to do this yourself I've re-uploaded the library with the names changed for you (although
> I doubt I'll get any thanks for it still, but ah well.)
> Hope this helps someone else once it circulates round the archives a bit.


....and then the same rigamarole for each of several other APIs you did
the same name reuse trick on. It's not like I'm able to just use your
code in isolation, nor can I afford to alter (and retest) the code of
the other contributors who *properly* used the same APIs within the project.


No, there's just not enough potential difference between yours and the
other code that for some yet-unknown reason simply can't do the job. I
can see inside that you're using almost the same calls as the code which
I had already specified (in the very first post!) wasn't working. IMO
the risk is too high that it'll just get the same invalid file handles
(-1) when it tries.



Bob
Mike D Sutton

2004-09-21, 8:55 am

> ...and then the same rigamarole <snip>

Yes, if you bothered to look at the code you'd see that those were changed too.

> No, there's just not enough potential difference between yours and the
> other code that for some yet-unknown reason simply can't do the job. I
> can see inside that you're using almost the same calls as the code which
> I had already specified (in the very first post!) wasn't working. IMO
> the risk is too high that it'll just get the same invalid file handles
> (-1) when it tries.


So you didn't actually want a solution then? Suit yourself then, works just fine here on .doc or any other files for that matter!
Good luck finding an alternative solution then *g*
Cheers,

Mike


- Microsoft Visual Basic MVP -
E-Mail: EDais@mvps.org
WWW: Http://www.mvps.org/EDais/


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com