Solved

How can I get a macro to get the string for the ChDir path form a file the local user can update.

Posted on 2013-06-03
6
408 Views
Last Modified: 2013-06-06
What I want to do is make a path.ini or path.config file where the user can enter the path of a folder where he or she wants the output files to be placed. Something like this I think ?
 Dim objFSO As Object, objFolder As Object, objFile As Object
 Dim sPath As String
 sPath= "C:\Program Files (x86)\myScript Folder\path.ini"

 ChDir = sPath

 ActiveWorkbook.SaveAs fileName:="Sample" & Format(Date, "_mm.dd.yyyy.") & "xls",   FileFormat:=xlText

 ActiveWorkbook.Saved = True
 ActiveDocument.Close

Open in new window


Than in the path.ini file the user can alter the path like:
C:\Program Files (x86)\myScript Folder\Files\

and where I have ChDir = sPath will use the path from the ini file to drop the file into that folder. I can't hard code the path because some of the users won't always be connected to the network and I need them to be able to set the path so they can upload or email the file to us.
0
Comment
Question by:GD_GRAY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:xFDSx
ID: 39217957
Oh ok... so the path.ini will only have the path...

Function Readini() As String
    Dim st As String
    Dim fob As Object
    Dim fin As Object
    Set fob = CreateObject("Scripting.FileSystemObject")
    Set fin = fob.OpenTextFile("C:\path.ini")
    st = oTS.Readline
    oTS.Close
    Set oTS = Nothing
    Set oFS = Nothing
    Readini = st
End Function

that will read 1st line and return it.. so on your code up there... do this

ChDir =readini

Also specify the ini path....


As always...

THE CODE(SOFTWARE) IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
0
 

Author Comment

by:GD_GRAY
ID: 39218056
You said Also specify the ini path.... do I put it in the function only or also in the Sub someplace ?
0
 

Author Comment

by:GD_GRAY
ID: 39218074
Also can it be set to read line 1 or line 2 ?
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 23

Expert Comment

by:Michael74
ID: 39218162
Another solution would be to have the user be prompted each time for a location

This function will prompt the user to select a folder and return the path

Michael

Function getFolder() As String

   With Application.FileDialog(msoFileDialogFolderPicker)
     .AllowMultiSelect = False
     .Show
     On Error Resume Next
     getFolder = .SelectedItems(1)
     Err.Clear
     On Error GoTo 0
   End With

End Function

Open in new window

0
 
LVL 1

Accepted Solution

by:
xFDSx earned 500 total points
ID: 39219822
Hey there; I meant that you have to specify the location of the path.ini in my code; so that it knows where the path.ini file is. In the case of my example path.ini is in the C drive, but you can put it anywhere...
If you want to read more than 1 line, you can just call the (st = oTS.Readline), every time you call readline it reads the next line in the file.... if you want to read more than that... well loop it..
0
 

Author Closing Comment

by:GD_GRAY
ID: 39226170
I was able to get your code to work but only by changing the ChDir =readini to ChDir=("C:\") & readini;  Im not sure whats going to happen if the user wants to save the file on a mapped drive ? Any ideas ?
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question