Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > VBA / Office Integration > Excel > Taking over a filename to a userform


Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2003, 07:59 AM
Artifi's Avatar
Artifi Artifi is offline
Centurion
 
Join Date: Mar 2003
Posts: 110
Default Taking over a filename to a userform


Hello

My procedure is running. A file is opened and then action is carried out with that opened file. It is all in one sub using three Input Boxes:

Code:
'... If DateiOffen = False Then Workbooks.Open FileName:=dateiRev2 '... abb = Application.InputBox("Ab welcher Spalte soll von Quelle kopiert werden?") '... biss = Application.InputBox("Ab welcher Spalte soll in Ziel eingefügt werden?") '... anzz = Application.InputBox("Wieviele Spalten sollen kopiert werden?") '... z = 0 For x = 1 To Range("A65536").End(xlUp).Row For y = 1 To Range("A65536").End(xlUp).Row t1 = Workbooks("Ziel.xls").Sheets("Tabelle1").Cells(x, 1) t2 = Workbooks(dateiRev2).Sheets("Tabelle1").Cells(y, 1) If t1 = t2 Then ' MsgBox t1 Workbooks("Ziel.xls").Activate Set IDRow1 = Columns(1).Find(What:=t1, lookat:=xlWhole) If Not IDRow1 Is Nothing Then xzcord = IDRow1.Row ' MsgBox xzcord End If ' MsgBox t2 Workbooks(dateiRev2).Activate Set IDRow2 = Columns(1).Find(What:=t2, lookat:=xlWhole) If Not IDRow2 Is Nothing Then xqcord = IDRow2.Row ' MsgBox xqcord End If For i = 1 To anz Workbooks("Ziel.xls").Sheets("Tabelle1").Cells(xzcord, i + bis - 1) = Workbooks(dateiRev2).Sheets("Tabelle1").Cells(xqcord, i + ab - 1) Next z = z + 1 End If Next y Next x MsgBox z

Instead of having three input boxes, I introduced a userform with three text boxes. The macro is the same until the file is opened an then I load the userform:

If DateiOffen = False Then Workbooks.Open FileName:=dateiRev2

UserForm1.Show
End Sub

The code of the userform is (nearly) identical to the code in the first macro, only the variables, anz, ab, bis are replaced with the appropriate textboxes (respectively).

The only problem is to carry over the variable dateiRev2, since these are two modules, two different subs, the userform sub doesn't know dateiRev2 which was defined in the first sub.

I could write the entire procedure in the userform code, but I don't want the userform appear too early.

Code:
Private Sub CommandButton1_Click() ' in this bracket? Workbooks("Ziel.xls").Activate z = 0 For x = 1 To Range("A65536").End(xlUp).Row For y = 1 To Range("A65536").End(xlUp).Row t1 = Workbooks("Ziel.xls").Sheets("Tabelle1").Cells(x, 1) t2 = Workbooks(dateiRev2).Sheets("Tabelle1").Cells(y, 1) If t1 = t2 Then ' MsgBox t1 Workbooks("Ziel.xls").Activate Set IDRow1 = Columns(1).Find(What:=t1, lookat:=xlWhole) If Not IDRow1 Is Nothing Then xzcord = IDRow1.Row ' MsgBox xzcord End If ' MsgBox t2 Workbooks(dateiRev2).Activate Set IDRow2 = Columns(1).Find(What:=t2, lookat:=xlWhole) If Not IDRow2 Is Nothing Then xqcord = IDRow2.Row ' MsgBox xqcord End If For i = 1 To TextBox3.Text Workbooks("Ziel.xls").Sheets("Tabelle1").Cells(xzcord, i + TextBox2.Text - 1) = Workbooks(dateiRev2).Sheets("Tabelle1").Cells(xqcord, i + TextBox1.Text - 1) Next z = z + 1 End If Next y Next x MsgBox z Unload UserForm1 Workbooks("Ziel.xls").Activate End Sub

I get error #9.

Last edited by Artifi; 03-28-2003 at 09:07 AM.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Two game plays selection on one userform rip Word, PowerPoint, Outlook, and Other Office Products 9 02-09-2003 09:00 AM
Unload of userform rip Word, PowerPoint, Outlook, and Other Office Products 10 01-08-2003 07:18 AM
Yoderic's Battle Arena -- Come And Play!! JDYoder Game Programming 4 12-11-2001 09:59 AM
mciSendString filename over a network Nesher API 8 11-21-2001 01:53 PM
Filename character check jdlf_wf4 General 3 03-21-2001 07:27 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->