To run a code in current directory

  • Thread starter Thread starter Hemanth
  • Start date Start date
H

Hemanth

i AM HAVING AN ISSUE .pLEASE HELP.

dOES ANYONE KNOW HOW TO RUN A CODE IN A WORKBOOK IRR3ESPECTIVE OF THE
DIRECTORY IT IS IN WHEN IT IS GETTING INPUT FROM FILE IN THE SAME
DIRECTORY BUT THE DIRECTORY KEEPS CHANGING.
 
Just get the directory of the active workbook, and use it with a variable in
your code.
E.g., to get the the active workbook name and path:
Activeworkbook.Path & " \" & Activeworkbook.Name, or
Activeworkbook.FullName
(the two expressions return the same string)

To save in another wkbook in the same folder:
fldr = Activeworkbook.Path
ActiveWorkbbok.SaveAs fldr & "\NewName.xls"

etc.


HTH,
Nikos
 
Please don't SHOUT. Many will not bother to even look if you do. This might
give you an idea.

Sub Backup() 'kept in personal.xls & assigned to toolbar button
On Error GoTo BackupFile
MkDir CurDir & "\Backup"
BackupFile:
With ActiveWorkbook
MyWB = .Path & "\BACKUP\" & .Name
.SaveCopyAs MyWB
.Save
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top