Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Looking for help with user input variable€¦

I have created a .bat file that prompts a user for a Project name. The
program then creates a project specific directory; copies a couple Excel
templates into the directory, then rename the templates to be project
specific and makes them .xls files based on the user information.

My question is there a way to have this .bat file update the templates, like
put the Project name in cell A1?

I guess what I am trying to say is that I cant seem to paste my variable
from my .bat into an excel worksheet. Is there a way to accomplish this, or
another way to make it happen?

Thank you in advance.

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Looking for help with user input variable€¦

You could have your .bat file create a small .txt file in the same folder
with the project name in it as a one-line entry. Then in the workbook's
_Open event you could put some code like this:

Private Sub Workbook_Open()
Dim myProjectName As String
Dim myFilenum As Integer
If ThisWorkbook.Path = "" Then
Exit Sub
End If
myFilenum = FreeFile()

If DIR(ThisWorkbookPath & Application.PathSeparator _
& "ProjectName.txt") < "" Then
Open ThisWorkbook.Path & Application.PathSeparator _
& "ProjectName.txt" For Input As #myFilenum
Input #myFilenum, myProjectName
Close #myFilenum
Else
Exit Sub
End If
On Error Resume Next
Worksheets("Sheet1").Range("A1") = myProjectName
If Err<0 Then
Err.Clear
End If
On Error Goto 0
End Sub

That code will work in a the .xls file(s) - won't when you create new from
the .xlt file initially. What it does is determine the path where the .xls
file is stored and then goes to look for a file named 'ProjectName.txt' in
that same folder, reads one line from it and stuffs it into Sheet1!A1

That code needs to go into the workbook event section. To get their
quickly, right click on the Excel icon immediately to the left of [File] in
the menu bar and choose View Code from the popup list. Copy and paste the
code into it.

It checks to make sure that the ProjectName.txt file exists and if not, then
just quits. Later it watches out for the case where there is not a sheet
with the name you've specified (Sheet1 in the code, change as required) in
the workbook, which might be the case if you've got users who get frisky
about renaming worksheets and such as that.

"Steve" wrote:

I have created a .bat file that prompts a user for a Project name. The
program then creates a project specific directory; copies a couple Excel
templates into the directory, then rename the templates to be project
specific and makes them .xls files based on the user information.

My question is there a way to have this .bat file update the templates, like
put the Project name in cell A1?

I guess what I am trying to say is that I cant seem to paste my variable
from my .bat into an excel worksheet. Is there a way to accomplish this, or
another way to make it happen?

Thank you in advance.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1,814
Default Looking for help with user input variable€¦

Thank you for your help! It is crazy how all this stuff works.

I have 2 other questions now.

1. How do I save the user imput to a text file? The variable is taken from
a "set /p project" in the .bat file.

2. Is there a way to make this _Open event to run only on the 1st time the
file is opened?

Thank you once again.


"JLatham" wrote:

You could have your .bat file create a small .txt file in the same folder
with the project name in it as a one-line entry. Then in the workbook's
_Open event you could put some code like this:

Private Sub Workbook_Open()
Dim myProjectName As String
Dim myFilenum As Integer
If ThisWorkbook.Path = "" Then
Exit Sub
End If
myFilenum = FreeFile()

If DIR(ThisWorkbookPath & Application.PathSeparator _
& "ProjectName.txt") < "" Then
Open ThisWorkbook.Path & Application.PathSeparator _
& "ProjectName.txt" For Input As #myFilenum
Input #myFilenum, myProjectName
Close #myFilenum
Else
Exit Sub
End If
On Error Resume Next
Worksheets("Sheet1").Range("A1") = myProjectName
If Err<0 Then
Err.Clear
End If
On Error Goto 0
End Sub

That code will work in a the .xls file(s) - won't when you create new from
the .xlt file initially. What it does is determine the path where the .xls
file is stored and then goes to look for a file named 'ProjectName.txt' in
that same folder, reads one line from it and stuffs it into Sheet1!A1

That code needs to go into the workbook event section. To get their
quickly, right click on the Excel icon immediately to the left of [File] in
the menu bar and choose View Code from the popup list. Copy and paste the
code into it.

It checks to make sure that the ProjectName.txt file exists and if not, then
just quits. Later it watches out for the case where there is not a sheet
with the name you've specified (Sheet1 in the code, change as required) in
the workbook, which might be the case if you've got users who get frisky
about renaming worksheets and such as that.

"Steve" wrote:

I have created a .bat file that prompts a user for a Project name. The
program then creates a project specific directory; copies a couple Excel
templates into the directory, then rename the templates to be project
specific and makes them .xls files based on the user information.

My question is there a way to have this .bat file update the templates, like
put the Project name in cell A1?

I guess what I am trying to say is that I cant seem to paste my variable
from my .bat into an excel worksheet. Is there a way to accomplish this, or
another way to make it happen?

Thank you in advance.

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
User Input Required axissm Excel Worksheet Functions 0 December 5th 06 01:45 PM
User Data Input DRANDON Excel Worksheet Functions 0 June 30th 06 08:12 PM
Have user input converted to uppercase in same cell as input? Shannonn New Users to Excel 1 June 20th 06 03:19 AM
Ask user for input during marco TSS Excel Discussion (Misc queries) 1 November 16th 05 10:57 PM
How can I calculate user input from a combo box into a formula? Quizboy Excel Worksheet Functions 0 November 16th 05 06:11 PM


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