OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 07-12-2011, 18:26
inkmachine
Guest
 
Posts: n/a
Default Help for a Newb to VBA on how to open directory?

Hi Everyone,

I'm new here and I'm a noobie when it comes to VBA code, but an old hat when it comes to CorelDraw. I've been using CorelDraw since version 3. No, not X3...version 3.0 LOL.

I'm familiar with coding such as HTML, XHTML, CGI, Perl, etc.
I have never worked with VBA or CorelScript and have just recently (within last 7 or 8 months) really started to see the light on how powerful VBA and macros can be when used with CorelDraw. What the heck has taken me so long...right??? lol

I have been looking through many macros that I have downloaded and am trying to learn little by little on how things work/function.

I work as an artist at a screenprinting shop and we have 2 directories that we open files from and save files to. Examples are:

s:\Final_Artwork
s:\Prelims

we use these two directories many many times throughout the day and I'd love to be able to create a macro so that we could open and save to these two default folders.

Example:

Open the S:\Prelims directory by hitting the Shift+F2 key. We then look for our file, find it, open it as usual.

Save the artwork by hitting Shift+F3 and it would bring up the save file dialog already in the S:\Final_Artwork directory. We just type in the name to save it as and hit enter or OK and it would be saved in the S:\Final_Artwork directory.

I can't even begin to tell you how much time this would save every day. Not having to hit Cntrl+O then dig down through directories to get to the S:\Prelims directory or Cntrl+S then digging to the S:\Final_Artwork directory would shave off a ton of time in total at the end of the day.

I know it probably sounds lazy...like...how much time can it take diging through directories right? But it adds up! LOL

Anyway, I have searched and searched and I might very well be searching for the wrong terminology since I am new to how all of this works.

SOOOOOO, to make a long story short....Is this something simple enough that one of you could whip it up or could point me in the right direction so that I can attempt to do this on my own and learn it?

I would love to be able to do this one way or the other.

I apologize for the loooooong message, but I wanted to be as descriptive as possible. Thanks to all of you for your help and time!

Best,
Jason Moore
Reply With Quote
  #2  
Old 07-12-2011, 21:51
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Open Directory

First, Great last name. :-) Second, welcome to the community I hope that we can save you some time here, that is what VBA is all about.

There is a Macro over on MacroMonster that handles the Open Dialog part. You can find it here: MacroMonster.com Hotfolders

That said, here is how you can do this yourself. I would suggest useing the CorelScriptTools.GetFileBox for both open and save. A quick sample of both methods:

Open a File:
Code:
Sub OpenMyFolder()
    Const sFolderPath As String = "S:\Prelims\" 'Set your folder here
    Dim sFileName As String 'The name of our file
    
    'Open file open dialog, you can change this to *.* to see all files
    sFileName = CorelScriptTools.GetFileBox("CorelDRAW Files (*.cdr)|*.cdr", "Select a file", 0, sFolderPath)
    
    'A quick check to make sure a file was selected
    If sFileName = "" Then
        Exit Sub
    End If
    
    'Open the file
    OpenDocument sFileName
End Sub
Save a File:
Code:
Sub SaveMyFolder()
    Const sFolderPath As String = "S:\Final_Artwork\" 'Set your folder here
    Dim sFileName As String 'The name of our file
    
    'Open file save as dialog, you can change this to *.* to see all files
    'Notice it is the same as above except we changed the 0 to 1
    sFileName = CorelScriptTools.GetFileBox("CorelDRAW Files (*.cdr)|*.cdr", "Save As", 1, sFolderPath)
    
    'A quick check to make sure a file name was entered
    If sFileName = "" Then
        Exit Sub
    End If

    'Save the file
    ActiveDocument.SaveAs sFileName
End Sub
A warning, the only error check I do is to make sure you have a file selected or a filename to save to. If you use the SaveAs you will not be prompted to overwrite if the file is all ready there, these are additions you will most likely want to consider, but since you are just beginning I wanted to keep the code very simple and clean.

Again welcome and have fun,

-Shelby Moore
Reply With Quote
  #3  
Old 08-12-2011, 08:09
inkmachine
Guest
 
Posts: n/a
Default

Hi,

LOL Great last names for sure! =)

Thanks for your help!!! I fiddled around with trying to get this to work. I've only messed with the 'Open File' version not the 'Save File' version yet =)

I've attached a screenshot of the code and the resulting 'Open' dialog box.

It seems that the Open dialog box is only going to the S:\Artwork directory and not actually inside the S:\Artwork\Prelims directory and instead it is adding the 'Prelims' inside the 'File Name:' text box area.

Is there something I'm missing? I'm going to go do some research and see if I can find something that might be causing it to not actually go into the S:\Artwork\Prelims directory and only into the S:\Artwork instead.

Thanks for your help and warm welcome to the community. I'm looking forward to learning as much as I can.

Best,
Jason Moore
Attached Images
 
Reply With Quote
  #4  
Old 08-12-2011, 11:47
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default FileOpen

Yep, you are missing a slash. Instead of: S:\Artwork\Prelims it needs to be S:\Artwork\Prelims\ that should fix the issue. :-)

-Shelby
Reply With Quote
  #5  
Old 08-12-2011, 17:41
inkmachine
Guest
 
Posts: n/a
Default

Hmmm, well, I added a slash after the Prelims and now I'm getting an error message that looks like what I have in the attached screenshot.

Any ideas?
Attached Images
 
Reply With Quote
  #6  
Old 10-12-2011, 01:15
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default Open Files

Did you select a file? In the Immediate Window type:
Code:
?sFileName
To see what is being returned, that should give a clue.

-Shelby
Reply With Quote
  #7  
Old 10-12-2011, 04:52
inkmachine
Guest
 
Posts: n/a
Default

Hi,

No, I couldn't select a file because when I ran the macro, the error above showed up. I never even got the open dialog box at all. I ran the macro and this error was what popped up.

Where do I type the ?sFileName?
Reply With Quote
  #8  
Old 10-12-2011, 07:12
Sablesword Sablesword is offline
Junior Member
 
Join Date: Aug 2006
Posts: 20
Default

Does the folder "Prelims" exist in the folder S:\Artwork ?

From your screenshots, it looks like you have a second folder
S:\Artwork\artwork as a subfolder of S:\Artwork

If your prelims folder is S:\Artwork\artwork\prelims rather than S:\Artwork\prelims, then you need to set the sFolderPath constant to "S:\Artwork\artwork\prelims\"
Reply With Quote
  #9  
Old 10-12-2011, 09:37
inkmachine
Guest
 
Posts: n/a
Default

Hi,

We have a main folder on our network named 'Artwork'
The folder structure inside that Artwork folder which is at S:\Artwork
is like this...

Artwork
>artwork
>automatic pics
>clipart
>digit embroidery
>distressed
>email
>embroidery
>eps
>fonts
>junk
>order forms
>prelims

So the prelims directory is S:\Artwork\Prelims or our server path is \\wserver\shared\artwork\prelims

I changed the sFolderPath to be S:\Artwork\Prelims\ and thats when I get the error that I posted the screenshot of in my last post.

So, I decided to try entering my server path which I listed above with a trailing slash after the Prelims... like this \Prelims\ and I still got the error message. The macro doesn't run and the file open dialog window does not open. Only the error.

So, I tried this.

For the sFolderPath I put S:\Artwork\Prelims\*.* and also the server path of \\wserver\shared\artwork\prelims\*.* and now the macro seems to work and actually goes into the Prelims folder.

But, as you can see in the screenshot that I posted, it's bringing up an odd shaped File Open Dialog window.

The folder and files are way up in the upper left corner and the rest of the screen is filled with a large blank grey area. Also, the 'File Name' box is then filled in with a *.* instead of being blank. That part really does not matter I guess. When we go into the Prelims directory, it's mostly to browse for files by date with the most recent files listed at the top of the list of files.

Do you know what would cause that to happen to the File Open dialog window and how it might be fixed?

Thanks again so much for helping me with this =)
Attached Images
  
Reply With Quote
  #10  
Old 10-12-2011, 09:39
inkmachine
Guest
 
Posts: n/a
Default

Oh, I forgot to mention, I am using Windows 7 Professional 32Bit....I didn't know if that might have some effect on the Open File Dialog box being all grey like that. Also, I can not resize that grey area.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing the current directory StianO CorelDRAW/Corel DESIGNER VBA 4 13-03-2009 04:49
Open directory of files with Error Handling... m31uk3 CorelDRAW/Corel DESIGNER VBA 1 10-02-2009 14:08
Search for Directory Name? bprice CorelDRAW/Corel DESIGNER VBA 2 22-08-2008 07:07
Move GMS Directory? bprice CorelDRAW/Corel DESIGNER VBA 2 15-07-2008 14:46
Where and how to define the save directory?! cristov CorelDRAW/Corel DESIGNER VBA 3 09-07-2008 19:27


All times are GMT -5. The time now is 03:49.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com