Home

Macros and Programming

 

CardboxForumsMacros and Programming > "variable folders"

variable folders

opening a folder with variable name

Current user: [none]
Register / Log In · Help

Posted By Post

greenkeeper

26-Jan-2016 15:30

I am trying to open up a folder where the folder name changes for each record i have on cardbox.

This is the half code that ive written

x = "NEW_REFERENCE"
Run "C:\Users\Greenkeepers SD\Documents\Analysis Sheets\x"

x is obviously different for each customer but cant get my head around how i can get that to open up the correct folder?

greenkeeper

26-Jan-2016 16:13

solved

greenkeeper

26-Jan-2016 16:45

expanding on that would the line of code needed for the creation of a folder if there isn't one already there be simple too?

x=new_reference

So it would be open analysis sheets\ find folder x, i no folder x create with name x and open

bert

26-Jan-2016 18:24

Not very clear...
However, if I invent a little, I understand you have a certain Cardbox Field in each record a name of a folder.
Then, you want to start a macro which launches Windows Explorer, showing the content of that folder.
If the folder does not exist, the macro has to add that folder with that name and Windows Explorer will show that empty folder (because it's just created).
Right?

greenkeeper

27-Jan-2016 09:14

yeah that is spot on

bert

27-Jan-2016 11:46

Well, first this is files and folders stuff. That is not complete in Cardbox Help.
That is also not necessary .It give you two important suggestions how to get this knowledge.

First is there the book VBScript in a Nutshell. Very good book for beginners!
But if you want cheaper: download from Microsoft the VBScript Documentation.
Find it here: https://www.microsoft.com/en-us/download/confirmation.aspx?id=2764
Install this file, you will see it will be a great help!
In no time you can find there that this is the macro you need:

'find your my documents folder
set wsh = CreateObject("WScript.Shell")
doc = wsh.SpecialFolders("MyDocuments")
If Right(doc, 1) <> "\" Then doc = doc & "\"

'folder in Cardbox record ---!!! only the name - no slash or backslash ---!!!
nme = Fields("FOLDERNAMEFIELD")

'foldername
fld = doc & nme & "\"

'check if folder exist, else ADD it
Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FolderExists(fld) = false then
   Set f = fso.GetFolder(doc)
   Set fc = f.SubFolders
   Set nf = fc.Add(nme)
end if

'launch Win Explorer with right folder
Run fld

Success
Bert Stortenbeker

greenkeeper

27-Jan-2016 12:35

yeh the download doesnt work....

greenkeeper

27-Jan-2016 13:17

ok so i have worked something that i can get to create the folder but it won't then open it up here the code

x = fields("NEW_REFERENCE")
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FolderExists ("\\GK1\Users\Greenkeepers SD\Desktop\Customer Files\North\"& x &"") = False Then
fso.CreateFolder ("\\GK1\Users\Greenkeepers SD\Desktop\Customer Files\North\"& x &"")
If fso.FolderExists ("\\GK1\Users\Greenkeepers SD\Desktop\Customer Files\North\"& x &"") = true then
Launch "\\GK1\Users\Greenkeepers SD\Desktop\Customer Files\North\"& x &""

tell me expected 'End' line 7 character1. Yet the last line is what i used to open the folder in a previous version of the macro when i knew the folder existed!

So lost!

bert

27-Jan-2016 13:20

Never heard of Google? Search on "vbscript 5.6 documentation"

You forgot at the end End if...

greenkeeper

27-Jan-2016 13:38

yeah i have but am really struggling to get my head around this at present. the end if at the end didnt make a difference like i thought it would have done too

Quick Reply

Please log in or register before trying to post a reply.

 
© 2010 Cardbox Software Limited   Home