Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7566759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:29:46+00:00 2026-05-30T14:29:46+00:00

I’m trying to create a program that can be used by other people. Currently,

  • 0

I’m trying to create a program that can be used by other people. Currently, my files are in the directory C:\Documents and Settings\jpmccros\Desktop\test

This directory contains my macro.xlsm, names.bat, and another sub-directory called Data.

The batch file names.bat does the following:

cd data

dir/b/o:n > names.txt

This does exactly what I want it to do. When I open the batch file (which is in the directory C:\Documents and Settings\jpmccros\Desktop\test\, the MS DOS Command Prompts starts in C:\Documents and Settings\jpmccros\Desktop\test\ then runs my commands and makes my file names.txt, and puts it exactly where I want it.

When I open up macro.xlsm and run the macro1, it calls the batch file to open.

This is my macro command:

Dim names_txt, names_bat, full_name, filename, folder As String
Dim position As Integer
Dim pathcrnt As String
full_name = ThisWorkbook.FullName
filename = ThisWorkbook.Name
position = InStr(1, full_name, filename, 1)
position = position - 1
folder = Left(full_name, position)

names_bat = folder & "names.bat"

Shell names_bat, vbMaximizedFocus

Now here is my problem: The macro actually opens the batch file, or at least it opens the MS DOS Command Prompt. However, when it opens the batch file, the initial directory is:

C:\Documents and settings\jpmccros\My Documents

I need this batch file and macro to be dynamic, therefore I need the batch file to open up its displaying directory. What’s going on with this? Is there a command I can write on my batch file? Is it something in VBA?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:29:47+00:00Added an answer on May 30, 2026 at 2:29 pm

    Your method of accessing the batch file using activeworkbook.path works. The VBA code finds it, relative to its current location, and opens it.

    However, the issue I was having was once VBA opens the batch file, the command prompt starts in the directory C:\Documents and Settings\jpmccros\My Documents\ every time.

    Your method does not bypass this issue. I did create a solution (and used your activeworkbook.path idea too). Instead of calling my batch file, I simply create one in VBA and print out a line cd var_activeworkbook.path & "\data". This way, I was able to have VBA search for the current directory and save it as a variable.

    Check it out:

    Dim pathcrnt As String, batch_file As Integer
    
    pathcrnt = ActiveWorkbook.Path
    batch_file = FreeFile()
    Open pathcrnt & "names.bat" For Output As #batch_file
    Print #batch_file, "cd " & pathcrnt & "\data"
    Print #batch_file, "dir/b/o:n > names.txt"
    Print #batch_file, "pause"
    Close #batch_file
    
    Shell pathcrnt & "names.bat", vbMaximizedFocus
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.