Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Shell Command - Net Time (Cannot create text file)


Hi All,

I am trying to create a text file containing the current data / time
and store it in the same folder as my workbook.

I am using the following code under Excel 2000 running under Win2000
Pro on a Win2000 Server domain:


Sub TimeCheck()

ShellCommand = "Net time " & ThisWorkbook.Path & "\_Time.txt"

MsgBox Shell(ShellCommand)

End Sub


The value returned in the MsgBox is obviously the program's task ID
(as expected), but the text file (time.txt) is not created in the
folder with the workbook.

There is no permissions issue - it won't work on a network drive nor
my hard disk where I have full permissions.


Any ideas?

Thanks,

Alan.




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Shell Command - Net Time (Cannot create text file)

Alan wrote:


Hi All,

I am trying to create a text file containing the current data / time
and store it in the same folder as my workbook.

I am using the following code under Excel 2000 running under Win2000
Pro on a Win2000 Server domain:


Sub TimeCheck()

ShellCommand = "Net time " & ThisWorkbook.Path & "\_Time.txt"

MsgBox Shell(ShellCommand)

End Sub


The value returned in the MsgBox is obviously the program's task ID
(as expected), but the text file (time.txt) is not created in the
folder with the workbook.

There is no permissions issue - it won't work on a network drive nor
my hard disk where I have full permissions.


Any ideas?

Thanks,

Alan.


I have got the impression you're trying to do something the hard way
when it can be easy. Does it *really* have to be the "net" time?

Sub TimeCheck()

Dim CurrentTime As Date
Const ForWriting = 2
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(ThisWorkbook.Path & _
"\_Time.txt", ForWriting, True)
CurrentTime = Now
f.Write CurrentTime
f.Close

MsgBox CurrentTime

End Sub

Please note: the True in OpenTextFile is for creating the file if it
does not exist.

--
To top-post is human, to bottom-post and snip is sublime.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Shell Command - Net Time (Cannot create text file)


"Amedee Van Gasse" wrote in message
...
Alan wrote:

I have got the impression you're trying to do something the hard way
when it can be easy. Does it *really* have to be the "net" time?

Sub TimeCheck()

Dim CurrentTime As Date
Const ForWriting = 2
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(ThisWorkbook.Path & _
"\_Time.txt", ForWriting, True)
CurrentTime = Now
f.Write CurrentTime
f.Close

MsgBox CurrentTime

End Sub

Please note: the True in OpenTextFile is for creating the file if it
does not exist.


Hi,

Once I have the net time, I will update the local client system time
returned by NOW().

Hence that is not an answer here.

Thanks for your idea though - any others?

Alan.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default Shell Command - Net Time (Cannot create text file)

Alan wrote:


"Amedee Van Gasse" wrote in message
...
Alan wrote:

I have got the impression you're trying to do something the hard way
when it can be easy. Does it really have to be the "net" time?

Sub TimeCheck()

Dim CurrentTime As Date
Const ForWriting = 2
Dim fs, f

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile(ThisWorkbook.Path & _
"\_Time.txt", ForWriting, True)
CurrentTime = Now
f.Write CurrentTime
f.Close

MsgBox CurrentTime

End Sub

Please note: the True in OpenTextFile is for creating the file if it
does not exist.


Hi,

Once I have the net time, I will update the local client system time
returned by NOW().

Hence that is not an answer here.

Thanks for your idea though - any others?

Alan.


Sure!
If I knew that in the first place, I would have given you the following
answer.

In the Microsoft Script Center, I found the following script:

----- CUT HERE -----
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
For Each objItem in colItems
Wscript.Echo "Day: " & objItem.Day
Wscript.Echo "Day Of the Week: " & objItem.DayOfWeek
Wscript.Echo "Hour: " & objItem.Hour
Wscript.Echo "Milliseconds: " & objItem.Milliseconds
Wscript.Echo "Minute: " & objItem.Minute
Wscript.Echo "Month: " & objItem.Month
Wscript.Echo "Quarter: " & objItem.Quarter
Wscript.Echo "Second: " & objItem.Second
Wscript.Echo "Week In the Month: " & objItem.WeekInMonth
Wscript.Echo "Year: " & objItem.Year
Next
----- CUT HERE -----

This is in VBScript and is for Windows XP/2003. 2000, NT4 and 98 don't
support the Win32_LocalTime class used in this script (AFAIK).
You should be able to rewrite this script to VBA, perhaps changing
every Wscript.Echo to Debug.Print or even MsgBox will do the job
(IDNTT).

The trick here is to change strComputer. Here it is "." which means the
local computer. Change this to the name of your time server in your
local network, et voila!

I assume stuff like permissions are also involved, but if you need more
help to get it working, you should really check out
news:microsoft.public.windows.server.scripting

Good luck!


--
Amedee Van Gasse using XanaNews 1.16.3.1
If it has an "X" in the name, it must be Linux?
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 188
Default Shell Command - Net Time (Cannot create text file)

"Amedee Van Gasse" wrote in message
...

Sure!
If I knew that in the first place, I would have given you the
following answer.

In the Microsoft Script Center, I found the following script:

----- CUT HERE -----
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from
Win32_LocalTime") For Each objItem in colItems
Wscript.Echo "Day: " & objItem.Day
Wscript.Echo "Day Of the Week: " & objItem.DayOfWeek
Wscript.Echo "Hour: " & objItem.Hour
Wscript.Echo "Milliseconds: " & objItem.Milliseconds
Wscript.Echo "Minute: " & objItem.Minute
Wscript.Echo "Month: " & objItem.Month
Wscript.Echo "Quarter: " & objItem.Quarter
Wscript.Echo "Second: " & objItem.Second
Wscript.Echo "Week In the Month: " & objItem.WeekInMonth
Wscript.Echo "Year: " & objItem.Year
Next
----- CUT HERE -----

This is in VBScript and is for Windows XP/2003. 2000, NT4 and 98
don't support the Win32_LocalTime class used in this script (AFAIK).
You should be able to rewrite this script to VBA, perhaps changing
every Wscript.Echo to Debug.Print or even MsgBox will do the job
(IDNTT).

The trick here is to change strComputer. Here it is "." which means
the local computer. Change this to the name of your time server in
your local network, et voila!

I assume stuff like permissions are also involved, but if you need
more help to get it working, you should really check out
news:microsoft.public.windows.server.scripting

Good luck!


Hi,

Well - I learnt a lot about server scripts which was very interesting!

I actually ended up solving it in a simpler way by using the command
line parameters of the 'net time' command - see below.

The following executes the command but also sets the client system
clock from the server clock at the same time, so I get where I want to
go in a single step.


Sub TimeCheck()

Shell ("net time \\server /set /yes")

End Sub


Thanks for your help - I really appreciate it.

Alan.






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell command MAx Excel Programming 2 June 4th 04 04:11 PM
xp shell command using vba Sudhendra Excel Programming 2 February 16th 04 05:56 AM
Application Process-Shell Command GarethG[_10_] Excel Programming 2 October 29th 03 01:35 PM
SHELL command Robin Clay[_3_] Excel Programming 3 October 17th 03 02:50 PM
Copying a file with VBA (or with a SHELL command) Franck V. Excel Programming 1 September 15th 03 07:46 PM


All times are GMT +1. The time now is 01:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"