Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Excel variable for path  (Read 23383 times)

0 Members and 1 Guest are viewing this topic.

Salmon Trout

  • Guest
Re: Excel variable for path
« Reply #30 on: September 22, 2009, 11:34:04 AM »
It is solved!!! You can use run a Sub at Workbook Open time, to read the text file and get the text line and put it in a cell.

Code: [Select]
Private Sub Workbook_Open()
Dim MyString, Homedrive, Homepath, Filename, Fullname
Homedrive = Environ("HOMEDRIVE")
 Homepath = Environ("HOMEPATH")
 Filename = "Excel-value.txt"
 Fullname = Homedrive & Homepath & "\" & Filename
Open Fullname For Input As #1
Input #1, MyString
Close #1
[A1] = MyString
End Sub

Here is a batch file to test it

Code: [Select]
@echo off
echo Send string to Excel
set folder=%HOMEDRIVE%%HOMEPATH%
set filename=Excel-value.txt
echo Folder: %folder%
echo File:   %filename%
set /p mystring="Enter string to import into Excel ? "
echo.
echo %mystring% > "%folder%\%filename%"
echo Contents of file:
type "%folder%\%filename%"
echo.
echo Ready to start Excel
pause
echo.
start /WAIT "" "S:\Test\Excel\Environ004.xls"
echo.
echo Excel finished
pause

And a picture

« Last Edit: September 22, 2009, 12:59:52 PM by Salmon Trout »