Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel Create Array Variable

Good afternoon - I have a stupid question for the VBA gurus:

I have some code that takes a file list of pdf documents and merges
the listed documents together. This works great, with the exception
that I have "hardcoded" the file list in the array variable.

What I would like to do is have the user select a list of pdf file
paths in Excel, then have some code that convert what is currently
selected into the array variable so that the rests of the code may
continue.

In other words, I currently have
myArray("c:\test1.pdf", "c:\test2.pdf", "c:\test3.pdf")

I can't figure out the code to take a selected list of files from
excel into this array. Say the file list is A1:A3 -
A1 - c:\test1.pdf
A2 - c:\test2.pdf
A3 - c:\test3.pdf
If the user selects these 3 cells, I'd like them to be able to click a
command button which will kick of the merge program, and pass the
contents of what is selected to myArray, as listed above.

Help??
Brian Limbert
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel Create Array Variable

If selection.Areas.count 1 then
msgbox "No go, quitting . . . "
exit sub
End if

vArr = Application.Transpose(Selection.Value)

--
Regards,
Tom Ogilvy

"Brian" wrote in message
om...
Good afternoon - I have a stupid question for the VBA gurus:

I have some code that takes a file list of pdf documents and merges
the listed documents together. This works great, with the exception
that I have "hardcoded" the file list in the array variable.

What I would like to do is have the user select a list of pdf file
paths in Excel, then have some code that convert what is currently
selected into the array variable so that the rests of the code may
continue.

In other words, I currently have
myArray("c:\test1.pdf", "c:\test2.pdf", "c:\test3.pdf")

I can't figure out the code to take a selected list of files from
excel into this array. Say the file list is A1:A3 -
A1 - c:\test1.pdf
A2 - c:\test2.pdf
A3 - c:\test3.pdf
If the user selects these 3 cells, I'd like them to be able to click a
command button which will kick of the merge program, and pass the
contents of what is selected to myArray, as listed above.

Help??
Brian Limbert



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Excel Create Array Variable

Chip - thanks for the speedy reply and quick solution. However, I'm
certain I'm missing something blatantly obvious. It works up to where I
try to evaluate the content of each value in the array -

As you prescribed I set this variable:
InsertFileArray = Application.Transpose(Selection.Value)

Then when I try to evaluate the first value in the array,
If vFile = InsertFileArray(0)
I receive a "Subscript out of range" error.

I've snipped a little piece of the code out. Do I have the array
declared incorrectly?

Thanks for the assistance,
Brian

Public Sub GetPDF()

Dim PDDocSource As Object
Dim PDDocTarget As Object
Dim PDDocInsertSource As Object
Dim PDDocInsertTarget As Object

Dim InsertFileArray As Variant
Dim vFile As Variant

TargetPath = "C:\Documents and Settings\blimbert\Desktop\"
TargetFile = "test.pdf"

If Selection.Areas.Count 1 Then
MsgBox "Nothing selected."
Exit Sub
End If

InsertFileArray = Application.Transpose(Selection.Value)

Set PDDocInsertSource = CreateObject("AcroExch.PDDoc")
Set PDDocInsertTarget = CreateObject("AcroExch.PDDoc")

For Each vFile In InsertFileArray
If InsertFileArray(0) = vFile Then 'Get the first pdf file in
the directory
If PDDocInsertSource.Open(vFile) < True Then
MsgBox "Unable to open the source PDF - " & vFile
End
End If
Else


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Excel Create Array Variable


OK - now I'm proving how much I don't know. I got this to work, by
changing the statement of

If InsertFileArray(0) = whatever

to

If InsertFileArray(1) = whatever

I thought 0 was always the first value in the array, instead of 1.

Please help the clueless?
Brian


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 783
Default Excel Create Array Variable

When an array is loaded from a worksheet range it is always a 1-based array.

Alan Beban

Brian wrote:

OK - now I'm proving how much I don't know. I got this to work, by
changing the statement of

If InsertFileArray(0) = whatever

to

If InsertFileArray(1) = whatever

I thought 0 was always the first value in the array, instead of 1.

Please help the clueless?
Brian


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel Create Array Variable

Arrays picked up this way are always 1 based, so the first element is

InsertFileArray(1)

--
Regards,
Tom Ogilvy

"Brian" wrote in message
...
Chip - thanks for the speedy reply and quick solution. However, I'm
certain I'm missing something blatantly obvious. It works up to where I
try to evaluate the content of each value in the array -

As you prescribed I set this variable:
InsertFileArray = Application.Transpose(Selection.Value)

Then when I try to evaluate the first value in the array,
If vFile = InsertFileArray(0)
I receive a "Subscript out of range" error.

I've snipped a little piece of the code out. Do I have the array
declared incorrectly?

Thanks for the assistance,
Brian

Public Sub GetPDF()

Dim PDDocSource As Object
Dim PDDocTarget As Object
Dim PDDocInsertSource As Object
Dim PDDocInsertTarget As Object

Dim InsertFileArray As Variant
Dim vFile As Variant

TargetPath = "C:\Documents and Settings\blimbert\Desktop\"
TargetFile = "test.pdf"

If Selection.Areas.Count 1 Then
MsgBox "Nothing selected."
Exit Sub
End If

InsertFileArray = Application.Transpose(Selection.Value)

Set PDDocInsertSource = CreateObject("AcroExch.PDDoc")
Set PDDocInsertTarget = CreateObject("AcroExch.PDDoc")

For Each vFile In InsertFileArray
If InsertFileArray(0) = vFile Then 'Get the first pdf file in
the directory
If PDDocInsertSource.Open(vFile) < True Then
MsgBox "Unable to open the source PDF - " & vFile
End
End If
Else


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Excel Create Array Variable



Thanks for the help and explanation. Two more questions to conclude
this topic:
1) Is there a way to make it so that you could do this fill this array
from a select **non-contiguous** range? It appears the transpose
function only works on a contiguos range.

2) How would I go about using the same type of result for an access
query table or query?

Thanks for all of your help - it is truly appreciated.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel Create Array Variable

#1
for a non-contiguous range, you would need to loop through the cells and add
the values one at a time to each element of the range.

#2
A variant variable can be passed an array. So I believe you can assign a
record to a variant and it will be passed as an array.

this article shows how to do it with DAO
http://support.microsoft.com/default...;en-us;q149254

rs.MoveLast
x = rs.RecordCount
rs.MoveFirst
'Return the records to an array variable.
varrecords = rs.GetRows(x)


I assume you could do something similar with ADO.

--
Regards,
Tom Ogilvy




"Brian" wrote in message
...


Thanks for the help and explanation. Two more questions to conclude
this topic:
1) Is there a way to make it so that you could do this fill this array
from a select **non-contiguous** range? It appears the transpose
function only works on a contiguos range.

2) How would I go about using the same type of result for an access
query table or query?

Thanks for all of your help - it is truly appreciated.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel Create Array Variable

Hi Brian,

I can't find a snipet of code I had that does this, but you'll find
that if you midify this:

Using the FileSearch object
This function uses the FileSearch object, which is not supported in
all versions of Excel. Unlike the previous version of the function,
this one returns the full path as well as the file name.

Also, be aware that some users have reported problems using the
FileSearch object.

Function NewestFile(Directory, FileSpec)
' Returns the full path and name of the most recent file in a
Directory
' That matches the FileSpec (e.g., "*.xls").
' Returns an empty string if the directory does not exist or
' it contains no matching files
Dim NumFound As Long
NewestFile = ""
With Application.FileSearch
.NewSearch
.LookIn = Directory
.FileName = FileSpec
NumFound = .Execute(SortBy:=msoSortByLastModified, _
SortOrder:=msoSortOrderDescending)
If NumFound 0 Then NewestFile = .FoundFiles(1)
End With
End Function

.... you should be able to build your array (with a bit of tinkering).

FileSpec should be something like "*.pdf"
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I create a dummy variable in Excel? Statistically Lost Excel Discussion (Misc queries) 1 April 19th 10 08:42 PM
Using COUNTA for a variable array Schannah Excel Worksheet Functions 5 July 22nd 08 05:02 PM
create a "variable array?" to report data Jeff Excel Discussion (Misc queries) 1 May 6th 08 08:44 PM
create a multivariable regression in excel without using array dls Excel Worksheet Functions 1 August 23rd 05 08:50 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


All times are GMT +1. The time now is 01:25 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"