pass workbook name to sub

P

Przemek

Hi,
In my addin I'm opening file through workbooks.open. Till now it's
allright. But when I want to pass workbook to other subs I'm receiving
error "subscript out of range". Here is my code:
#addin
Sub RaportPlat()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Filters.Add "Raport p³atno¶ci", "*.xls", 1
.Show
End With
Workbooks.Open Filename:=fd.SelectedItems(1)

Copy_Rows_Wejscie_Nieuslugi (fd.SelectedItems(1))

passing workbook to sub:

Sub Copy_Rows_Wejscie_Nieuslugi(WorkbookName As String)
'workbooks(WorkbookName).Activate
Dim RngCol As Range
Dim i As Range
Workbooks(WorkbookName).Worksheets("wejscie nieuslugi") = ActiveSheet

here i'm receiving error.

How can I resolve it, please?

TIA

Przemek
 
B

Bob Phillips

Hi Przemek,

Probably because the name is path and name. Try

Copy_Rows_Wejscie_Nieuslugi (Activeworkbook.Name)


--

HTH

RP
(remove nothere from the email address if mailing direct)


Hi,
In my addin I'm opening file through workbooks.open. Till now it's
allright. But when I want to pass workbook to other subs I'm receiving
error "subscript out of range". Here is my code:
#addin
Sub RaportPlat()
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
.Filters.Add "Raport p³atno¶ci", "*.xls", 1
.Show
End With
Workbooks.Open Filename:=fd.SelectedItems(1)

Copy_Rows_Wejscie_Nieuslugi (fd.SelectedItems(1))

passing workbook to sub:

Sub Copy_Rows_Wejscie_Nieuslugi(WorkbookName As String)
'workbooks(WorkbookName).Activate
Dim RngCol As Range
Dim i As Range
Workbooks(WorkbookName).Worksheets("wejscie nieuslugi") = ActiveSheet

here i'm receiving error.

How can I resolve it, please?

TIA

Przemek
 

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