I am stuck with vba excel macro. What I need is to have a macro that does the following two things:
creates an empty text file that will be stored either in user's %USERPROFILE%\filename.txt or %TMP%\filename.txt.
output the contents of the Shell() command to a file created in point 1 above. For example a DOS equivalent of "ipconfig > %TMP%\filename.txt", or similar DOS commands.
The %USERPROFILE% and %TMP% will contain spaces as the usernames are "First_NameLast_Name".
I've been searching some examples of this simple and trivial task, but I am unable to achieve what I want. I get runtime error 53 file not found. An example code that i've tried:
Sub CreateAfile()
Dim MyPath As String
MyPath = Environ$("TMP") & "\filename.txt"
'MsgBox MyPath
Call Shell("ipconfig > " & MyPath, vbHide)
End Sub
The MyPath variable above seem to generate the correct filename path, at least when used by the MsgBox. However it doesn't seem to work when called from the Shell().
Could someone help me to achieve my goals?
Thanks