Print Failure - Default File Location

G

Guest

Below is a subset of some code that I have for a macro that opens and prints
files in a specific directory on a users C:\drive. The macro first counts
the files then opens them and prints the applicable pages. Everything work
fine unless a user has Tools-Option-General-Default File Location set to
anything other than the C:\drive (If it is set to the C:\drive, the directory
within the C:\drive doesn't seem to matter). If I set a watch on
directoryname it shows "C:\ProPupload\Do", but exits the count routine after
the first pass if there are no files in the non C:\drive default file
location, or the code bombs if there are files in the non C:\drive default
file location.

Is there something else I need to add to make sure that the pointer gets re
directed to C:\? Any help is greatly appreciated.

Sub aaaOpenandPrint()
Dim result As Integer
Dim noOfFiles As Integer
Dim arrayFiles() As String
Dim name_text As String
Dim count As Integer
Dim f As String
'define the location of the boe Do files
directoryname = "C:\ProPupload\Do\"
'get a list of the files to process in the DO folder
ChDir directoryname
count = 0
f = Dir$("*")
Do While Len(f) > 0
count = count + 1
ReDim Preserve arrayFiles(1 To count)
arrayFiles(count) = f
f = Dir$()
Loop
noOfFiles = count
'---------------------------------------------------------------------
'open one file at a time and format the report
'
count = 1
Do While count < noOfFiles + 1
Workbooks.Open Filename:=arrayFiles(count)
printfilename = arrayFiles(count)
count = count + 1
'Start printing
Windows(printfilename).Activate
 
G

Guest

Thanks!!!! I put in ChDrive "C" before the ChDir ands it works great.
Didn't realize that ChDir didn't change the default drive as well. This will
make a couple of users very happy. Thanks again.

--
Lee Kirts


Tom Ogilvy said:
ChDrive directoryname
ChDir directoryname

would be my guess
 

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

Top