LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #11   Report Post  
Posted to microsoft.public.excel.misc
Jim Hicks
 
Posts: n/a
Default Open File within a macro

Rob,

I don't know if this helps but open an explorer window and type "desktop" on
the address bar.
Click "start" "run" and type in desktop.
open a command prompt and type desktop....WTF....gotta look at that
again...my machine is trying to do something with a vbs...shouldn't
be...ignore this line...
open a command prompt and type set this will show the enviornmental
variables. the desktop path for any logged in user can be determined by
examining the user profile
enviornmental variable or the temp or appdata variables. the desktop is
always(usually) located in the same tree structure so if you can determine
the SETting you are half way there.

a newbie example would be to
shell "set c:\set.txt"
open c:\set.txt for input as #1
while not Eof(1)
'loop through file to look for the text and get path, then modify path to
point to the desktop...

wend
close #1


Another option would be to find out the username logged in and point to the
default path for that user...you would have to verify that the profiles are
stored in a predictable manner (as is usually the case in windows with
normal profiles)

there is code out there that will tell you the logged in user name... I
can't seem to find it right now...
just add the "C:\Documents and Settings\XXXXX\Desktop\


since I can't find the code here is another way... I will look again later
on...
here is the one that finds the computer name...I think it would be similar
but can't remember..

'get computername
Dim strComputerName As String * 255
Dim lngComputerNameLength As Long

lngComputerNameLength = Len(strComputerName)
If GetComputerName(strComputerName, lngComputerNameLength) < 0 Then
currentuser$ = Left$(strComputerName, lngComputerNameLength)
Else
currentuser$ = Err.LastDllError
End If



run (xp) gpresult...the 5th line or so should show
RSOP results for DOMAIN NAME\USERID on MACHINE NAME: Logging Mode
------------------------------------------------------------
or....
just open a command prompt and type dir
see the default path is to the profile.....


and finally.....opening a file
if you do a run C:\Documents and Settings\USERNAME\Desktop\1.txt
you could run it in a dos prompt also but don't forget the Quotes for long
filenames (spaces won't work in the path otherwise)
this would open the 1.txt file on the desktop in notepad (default
application)
this can be done programattically using the shell, through a batch file or
dos prompt...


I hope this helps a little....BTW I am a newbie programmer (been that way
since the Atari 400)
there are probably much better ways to do this stuff but it is interesting
to see all the ways you can access the profile and files in XP
do a search in the Windows folder for all files and check out some of the
exe's hidden in windows...
also look at MSC like gpedit.msc.
check out the 2 different dos prompts...start-run-command and start-run-cmd
also

Anyhoo, I hope this info helps a little.....but listen to the experts before
me.......


"Rob" wrote in message
...
I would like to know the code (to put within some other code), which will
run the Open file dialogue, & pointing to the desktop, so that a text file
can be selected.
(Then, I need that selected text file opened so that the macro will do
some action on that file and revert back to the workbook for mor action.)
I found something in help, which opens the dialogue box, but it does not
open the file, just brings up a message box that tells me the file I've
selected.

Furthermore, is there a way for that code to point to any desktop no
matter where it is located in the Windows Explorer tree? (As I plan to use
the workbook on various machines.)

Rob



 
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
Open last file with certain file name GEORGIA Excel Discussion (Misc queries) 5 April 13th 06 01:48 PM
Macro syntax to open file in current explorer folder [email protected] Excel Discussion (Misc queries) 4 January 11th 06 12:07 PM
Weird File Open/Save As Behavior [email protected] Excel Discussion (Misc queries) 0 December 9th 05 02:26 AM
How to stop file open macro prompt after deleting all macros? twor57 Excel Worksheet Functions 2 November 29th 05 05:00 PM
Macro to open specific File tamato43 Excel Discussion (Misc queries) 4 May 18th 05 09:42 PM


All times are GMT +1. The time now is 03:36 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"