Excel VBA Kopierern durch .Workbooks . .. oder .Windows .. OOP Methode

DocAElstein

Banned user
Joined
May 24, 2014
Messages
1,336
'
'‚. Hello Leute. … ---o00o---`(_)`---o00o---
'‚.
'‚. Ich bin eine Neuling zu Excel VBA und versuche die Theorie etwas besser zu verstehe.
'‚.
'‚. Ich wollte an einfach Direkt Methode um die Werte aus einer Cell in eine
'‚ Excel Mappe
(Mappe2) zu kopieren in eine andere Excel Mappe (Mappe 1).
'‚ Ich wollte die Code selber schreiben durch eine verstand von VBA,
'‚ statt einfach beim benutzen Makro aufzeichnen
'‚ .
'‚. Das ist (soll) ja etwas einfach und ich hab es geschafft.
'‚ Allerdings ich verstehe nicht warum manche Methode die ich probiere nicht funktioniere.
'‚ Es liegt wahrscheinlisch in die Objekt/Klasse/Orientiren Konzept das ich noch nicht ganz verstehe.
'‚ . (Oder ist es so dass man kann nur eine Value geben oder nehmen von eine Mappe
'‚ das nicht aktivieret ist, mit die
Windows .Aktive cell Methode? -
'‚ Man kann also nicht angreifen an cells wenn eine Mappe nicht Aktivieret ist?)
'.
'. Eventuelle kann eine Profi mir Hilfen:-
'.
''. Die folgenden 4 Codes sind eine versuche an an einfach direkt Methode.
''. Allerdings nur die vierte scheint bei mir zu funktionieren!
''.
''‚…………… ……….---o00o---`(_)`---o00o---
''.------ 1'.

Sub WorkbooksCellsMethodDirekt()
Excel.Application.Workbooks("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value
End Sub



'.
'. -------------- 2
'.

Sub WorkbooksActiveCellMethodDirekt()
Excel.Application.Workbooks("Mappe1.xlsm").Application.ActiveCell.Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.ActiveCell.Range("a1").Value
End Sub


'.
'. ------------------------ 3
'.

Sub WindowsCellsMethodDirekt()
Excel.Application.Windows("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= Excel.Application.Windows("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value
End Sub


'.
'. --------------------------------------- 4
'.

Sub WindowsActiveCellMethodDirekt()
Excel.Application.Windows("Mappe1.xlsm").Activate
Excel.Application.Windows("Mappe1.xlsm").ActiveCell.Range("a1").Value _
= Excel.Application.Windows("Mappe2.xlsm").ActiveCell.Range("a1").Value
End Sub
'.
'. ----------------------------------------
'.
'. Es sieht also als ob nur die
Windows "Objekt" hat eine extra Activecell
'. statt nur Application.Activecell zu verfugen. Irgendwie macht das die unterscheid!!!.
'.
' (Bzw.
Workbooks hat .Application.Cells und .Application.ActiveCell.
'. Windows hat auch dieses .Application.Cells und .Application.ActiveCell,
'. allerdings Windows hat an extra .ActiveCell das Workbooks nicht hat!?!?)
'.
'. Kann jemand erkläre das mir!!?!
'.
'Danke, Alan Elston.
'. Hof,Bayern den 22.05.2014
'. Email DocAElstein@t-online.de
'.............
'.
'. P.s. Eine mehr komplizieret Methode mit eine zwischen Lager funktionieret bei
'. jede 4 Methode. Bzw. Die folgenden 4 Codes funktionieren alles Einbahn frei!!
'.
'.----------- ---o00o---`(_)`---o00o---


Sub WorkbooksCellsMethodMitZwischenLager()
Dim ZwischenLager As Double

Excel.Application.Workbooks("Mappe2.xlsm").Activate

Let ZwischenLager _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value

Excel.Application.Workbooks("Mappe1.xlsm").Activate

Excel.Application.Workbooks("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= ZwischenLager
End Sub
'.
'. -------------------------------------------
'.


Sub WorkbooksActiveCellMethodMitZwischenLager()
Dim ZwischenLager As Double

Excel.Application.Workbooks("Mappe2.xlsm").Activate

Let ZwischenLager _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.ActiveCell.Range("a1").Value

Excel.Application.Workbooks("Mappe1.xlsm").Activate

Excel.Application.Workbooks("Mappe1.xlsm").Application.ActiveCell.Range("a1").Value _
= ZwischenLager
End Sub
'.
'. ----------------------------------------
'.

Sub WindowsCellsMethodMitZwischenLager()
Dim ZwischenLager As Double

Excel.Application.Windows("Mappe2.xlsm").Activate

Let ZwischenLager _
= Excel.Application.Windows("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value

Excel.Application.Windows("Mappe1.xlsm").Activate

Excel.Application.Windows("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= ZwischenLager
End Sub
'.
'. -------------------------------------------
'.

Sub WindowsActiveCellMethodMitZwischenLager()
Dim ZwischenLager As Double

Excel.Application.Windows("Mappe2.xlsm").Activate

Let ZwischenLager _
= Excel.Application.Windows("Mappe2.xlsm").Application.ActiveCell.Range("a1").Value

Excel.Application.Windows("Mappe1.xlsm").Activate

Excel.Application.Windows("Mappe1.xlsm").Application.ActiveCell.Range("a1").Value _
= ZwischenLager
End Sub
'. -------------------------------------------------
'
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
'' An / To :- MrExcel VBA Excel Forum (Deutschland)
'' Von / From :- Alan Elston
'' Hallo,

'' Ich bin , Alan, die das die fragen ja hin gestellt vorgestern….
'' Zum Spaß hatte ich die fragen gleich in English gestellt,
'' in die erste MrExcel Forum „ Excel Questions
'' All Excel/VBA questions“
''
'' … In der zwischen Zeit hat „MrExcel“, bzw. die Moderator
'' Andrew Poulsom sehr schnell und klar mehrmals geantwortet
'' und Ich denk ich verstehe jetzt ja das Problem.
'' Falls es euch interessieret und Du kann ja English lesen es lohnt
'' sich an zu Schauern unter link:-

'' http://www.mrexcel.com/forum/excel-...workbooks-windows-oop-method.html#post3818451
'' Es ist aber etwas lange, und ich wollte ja selber es nochmal klar in
'' meine (unterfahrend VBA) kopf haben. Deswegen, zum Spaß
'' verkürz ich die Antwort hier:-
''
'' Es gibt zwei teil zu meine Antwort, ..Erstens die einfach Lösung,
'' mit die Cells Methode
'' . .. .. Zweitens eine bisschen Hintergrund und was Interessent
'' die auskam über OOP als ich fand warum ich auf falscher Weg gegangen war.
'' mit die Active Cell methode

''
'' Erstens,
'' ja, ich war zu blöd und hab vergessen die Worksheet
'' in die Code zu schreiben. Dann irgendeiner die folgender einfach
'' Code klappt um zum Beispiel die Werte von cell B1 in
'' Tabelle1, Mappe2 zu cell A1 in Mappe1, Tabelle1
''
''.------1b

Sub WorkbooksWorksheetsAndrewPoulsomCellsMethodDirect()
Excel.Application.Workbooks("Mappe1.xlsm").Worksheets.Item(1).Cells(1, 1).Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Worksheets.Item(1).Cells(1, 2).Range("a1").Value
End Sub
'.
'. ------------2b

Sub AndrewPoulsom2()
Workbooks("Mappe1.xlsm").Worksheets("Tabelle1").Range("A1").Value _
= Workbooks("Mappe2.xlsm").Worksheets("Tabelle1").Range("B1").Value
End Sub
'.
'. ---------------------3b

Sub AndrewPoulsom3()
Workbooks("Mappe1.xlsm").Worksheets.Item(1).Range("A1").Value _
= Workbooks("Mappe2.xlsm").Worksheets.Item(1).Range("B1").Value
End Sub
'.
'.-----------------------------4b

Sub AndrewPoulsom4()
Workbooks("Mappe1.xlsm").Worksheets.Item(1).Cells(1, 1).Range("A1").Value _
= Workbooks("Mappe2.xlsm").Worksheets.Item(1).Cells(1, 2).Range("A1").Value
End Sub
'.
'
'.--------------------------------------------6b

Sub WorkbooksCellsMethodDirectAlanElstonAndrewPoulson()
Excel.Application.Workbooks("Mappe1.xlsm").Worksheets("Tabelle1").Cells(1, 1).Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Worksheets("Tabelle1").Cells(1, 2).Range("a1").Value
End Sub
''
'' ………………………………----------------___________
''

'' Zweitens warum mit die Active Cells Methode falsch gegangen war..
'' Kurz gesagt, anderes zu wie oft behauptet in Bücher, Kurz usw.
'' mit die … „ OOP „dot“ . „… Code man geht nicht immer
'' beim links nach rechts . Code schreiben unter
'' in eine Objekt Hierarchie!! Man kann ja doch hin und
'' hier wie in alte Programmierung
'' Die Application Objekt bietet an so eine Möglichkeit,
'' und das ist warum es taucht so oft überall in die Excel Objekt Library
'' Es gibt aber nur eine Application Objekt und damit nur eine
'' Application.ActiveCell ( und nur einer Application.Cells )
'' Dieses Application kann aber überall bemützt vorbei
'' man dann flitz zurück über in die Hierachy und damit kann eine Teil von
'' die vorherigen Code ignorieren, bzw. irrelevant machen!!
'' Damit meine ActiveCell und Application.Cells Methode Code ;- ……
''

'‚…………… ……….---o00o---`(_)`---o00o---
'.-----1

Sub WorkbooksCellsMethodDirekt()
Excel.Application.Workbooks("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value
End Sub
'.
'. ------2

Sub WorkbooksActiveCellMethodDirekt()
Excel.Application.Workbooks("Mappe1.xlsm").Application.ActiveCell.Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.ActiveCell.Range("a1").Value
End Sub
'.
'. ---------3

Sub WindowsCellsMethodDirekt()
Excel.Application.Windows("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= Excel.Application.Windows("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value
End Sub

''
'' ….. hab ja nicht funktionieret, weil alles da in grau geschrieben
'' war ignorieret weil die Code hat sich zurück geflitzt üben in
'' die Hierarchie zum Application. Es gibt also nur einer

'' Application.Activecell und nur einer Application.Cells
'' und es war die von die zu die zeit aktivieret Workbook und
'' worksheet. Workbooks und Worksheets hab keine
'' Active cell
'' Das hat mir überrascht. Man kann aber quasi habe so viele
'' Workbook active cells wie man will mit die

'' Windows( ).Activecell wenn man die workbook Name in die
'' ( ) schreibt. Dann hat man so weil active cells wie offen workbooks,
'' ohne das die workbooks aktivieret muss.

''
''
''
'' Evtl. Drittens und zu gute letzte..

'' Vielleicht ich schreib laute Blödsinn – ich bin ja Anfänger.
'' --irgendjemand kann mir gern korrigieren!!
''
'' ..Bis dann
'' Alan Elston
'' Hof, Saale
'' Bayern
'' ( Email
Doc.AElstein@t-online.de )
''
''
'' P.s. Bitte endschuldigen meine schlechter Deutsch.. Ich bin ja Engländer
''
''
 
Upvote 0
Example 1 / Beispiel 1:

Code:
Excel.Application.Workbooks("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value

If you are writing the VBA to be run from a workbook and not from another application then you do not need to prefix the workbooks collection. You should not have the .Application object stuck in the middle of your object path. Also you do not need to specify the .Range("A1") after the .Cells property. And you need to specify the WORKSHEET object in your object path.

Wenn Sie schreiben, um den VBA aus einer Arbeitsmappe und nicht von einer anderen Anwendung ausgeführt werden, dann brauchen Sie nicht, um die Arbeitsmappen Sammlung voranstellen. Sie sollten nicht die. Anwendungsobjekt in der Mitte des Objektpfad fest. Auch brauchen Sie nicht, um die. Range ("A1") nach dem. Cells-Eigenschaft angeben. Und Sie müssen das Arbeitsblatt-Objekt in Ihrem Objekt Pfad angeben.

Code:
Workbooks("Mappe1.xlsm").Worksheets("Erste").Cells(1, 1).Value = Workbooks("Mappe2.xlsm").Worksheets("First").Cells(1, 2).Value


Example 2 / Beispiel 2:

Code:
Sub WorkbooksActiveCellMethodDirekt()
Excel.Application.Workbooks("Mappe1.xlsm").Application.ActiveCell.Range("a1").Value _
= Excel.Application.Workbooks("Mappe2.xlsm").Application.ActiveCell.Range("a1").Value
End Sub

The ActiveCell property returns the active cell in the active workbook. There is only one. There is not a "ActiveCell" on a non-active worksheet. Excel does store which cell was selected or active on every sheet at the time it lost focus. And it tracks this information for every worksheet in every workbook. But I have never seen any way to access that information through the Excel object model.

Die Active Eigenschaft gibt die aktive Zelle in der aktiven Arbeitsmappe. Es gibt nur eine. Es ist kein "Active" auf einem nicht-aktiven Arbeitsblatt. Excel macht speichern, die Zelle auf jedem Blatt an der Zeit, den Fokus verloren ausgewählt wurde, oder aktiv. Und es verfolgt diese Informationen für jedes Arbeitsblatt in jeder Arbeitsmappe. Aber ich habe noch nie eine Möglichkeit, diese Informationen durch das Excel-Objektmodell zugreifen gesehen.

Code:
Sub WorkbooksActiveCellMethodDirekt()
    '// this code is dead / Dieser Code ist tot
End Sub

Example 3 / Beispiel 3:

Code:
Sub WindowsCellsMethodDirekt()
Excel.Application.Windows("Mappe1.xlsm").Application.Cells(1, 1).Range("a1").Value _
= Excel.Application.Windows("Mappe2.xlsm").Application.Cells(1, 2).Range("a1").Value
End Sub

Similar to Example 1. But since a Window object does not have a WORKSHEETS collection, you would be forced to use the ActiveSheet property to retrieve a worksheet whose cells you could target.

Ähnlich wie in Beispiel 1. Aber da ein Window-Objekt nicht über ein Worksheets-Auflistung, würden gezwungen, die Active Eigenschaft verwenden, um ein Arbeitsblatt, deren Zellen, die Sie als Ziel haben könnte abzurufen.


Code:
Sub WindowsCellsMethodDirekt()
Windows("Mappe1.xlsm").ActiveSheet.Cells(1, 1).Value = Windows("Mappe2.xlsm").ActiveSheet.Cells(1, 2).Value
End Sub

Example 4 / Beispiel 4:

Code:
Sub WindowsActiveCellMethodDirekt()
Excel.Application.Windows("Mappe1.xlsm").Activate
Excel.Application.Windows("Mappe1.xlsm").ActiveCell.Range("a1").Value _
= Excel.Application.Windows("Mappe2.xlsm").ActiveCell.Range("a1").Value
End Sub

Yes. This would have worked. You had extra references that were not needed. But the code should have executed and produced the desired results.

Ja. Dies würde gearbeitet haben. Sie hatten extra Referenzen, die nicht benötigt wurden. Aber der Code ausgeführt haben und die gewünschten Ergebnisse gebracht.


Code:
Sub WindowsActiveCellMethodDirekt()
Windows("Mappe1.xlsm").Activate
ActiveCell.Value = Windows("Mappe2.xlsm").ActiveCell.Value
End Sub
 
Upvote 0
From Alan
To Greg

. Thanks, that was a very clear and good reply. (And thanks for writing in English and German.!!). I think I understand everything that you said.

A bit of Feedback on what you wrote:-

. ----- The point about specifying the Worksheet: Yes, that was just an oversight by me that I forgot to include it. I tend only to use one Table in a workbook so I just forgot that there was more than one!!


. ----- About unnecessary extra code. I realised that, but as I am learning It helped me to remember the Hierarchy OOP system and also what options are available (For example including Range (“ “) helps me to remember I could have accessed a different cell or cells for example with Range (“A1:B2”) etc. Having said that your comments on why other parts of the code were not necessary were helpful in me understanding further how it all works and fits together.

. -------. The point about only one Active cell and not being able to access information on others??? I took this point a bit further on another forum...Link/ Thread :- ht tp://www.mrexcel.com/forum/general-excel-discussion-other-questions/780223-many-active-cells-you-like-once%85-o00o-%60-_-%60-o00o-oop-hierarchy.html . Maybe as I’m a beginner I’ve missed something? , - but it appears to me that you can access everything about the cell which was last activated on all (open) Workbooks. I explain how in that link/ Thread, and it’s been working fine for me. For example if I have lots of workbooks open, I can go through them and select the information I want from all of them and then access all this information in one go using the method I described in that link / Thread..... or putting it another way, say I have 3 workbooks open and I go through and select any cell in any sheet, in every workbook that has a 1 in it. Then I can use the following code to add those numbers ( I tested it and it gives the correct answer, 3) or, for example find the column index for one of the workbooks. (The code can be written in any workbook. This Workbook does not have to be activated.


Code:
[B]Sub WindowsLastActiveCellEnglish()
[/B] 
[COLOR=#008000][B]' Have as many active cells as you want and access them[/B]
[B]' For example the Sum of the 3 values[/B][/COLOR]
[B]Dim x As Double[/B]
[B]Let x = Windows("Book1").ActiveCell.Value _[/B]
[B]+ Windows("Book2").ActiveCell.Value _[/B]
[B]+ Windows("Book3").ActiveCell.Value[/B]
 [COLOR=#008000]
[B]'   Get a Property from any WindowsActiveCell[/B][/COLOR]
[B]Dim y As Integer[/B]
[B]Let y = Windows("Mappe1").ActiveCell.Column[/B]
 
[B]End Sub[/B]



.. ------ Your point about “ should not have the .Application object stuck in the middle of your object path “ I’m still not quite sure about that one. That’s discussed as well in the above Link / Thread. See also my and Andrew Poulsoms comments on that in my English version of this link / Thread http://www.mrexcel.com/forum/excel-...workbooks-windows-oop-method.html#post3818451 . - Basically I get the feeling VBA is not really an object orientated program, just something that looks Very similar!?!?
. _____________________________________________________________________________

Von Alan
An Greg

. Danke, das war eine sehr gut und Klar Antwort. (Danke auch das Sie in Deutsch und Englisch geschrieben habe!!). Ich denke ich habe verstanden alles was Sie geschrieben habe.

Eine bisschen Feedback dazu:-

. -------- Uber referenzieren die Arbeitsblatt. Ja ich hab das einfach vergessen / verbummelt!! – Üblicherweise bemützt ich nur eine Tabelle, deswegen habe ich es einfach vergessen das es mehrerer gibt!!

. -------- Uber überflüssig Code. Ich wusste es, aber es Hilft mir beim lernen um zu erinner die OOP Hierarchie System. (Auch mit die extra Range(„ „) es erinnert mich das ich weiterer Möglichkeit habe um mehrere oder anderer cell zu referenzieren mit Range(„a1:B2“) usw. Trotzdem ihrer Kommentar an warum es überflüssig war was hilfsreich weil ich damit besser verstehe wie alles funktionieret.

. ----- Die Punkt über nur " eine ActiveCell und das man nicht auf die Info von eine letzter bemützt cell in eine nicht aktivieret workbook kann "…..?? Ich habe diese Punkt schon weiter diskutieret in eine anderer Forum / Link
http://www.mrexcel.com/forum/genera...nce%85-o00o-%60-_-%60-o00o-oop-hierarchy.html Evtl. als Anfänger vermiss ich was. Aber wenn ich mich nicht tausch, man kann doch alles über die letzter bemützt cell ausfinden / angreifen. Ich erkläre wie in das link. Ich bemützt diese Methode schon sehr erfolgreich: Ich habe viele Workbooks offen . In jede selektier ich die Info Ich will, bzw. aktivieren die cell. Dann auf einmal greif ich an alles was ich will gleich zeitig mit VBA. Ich erklär wie darin. Oder anderes gesagt: Sag zum Spaß man hat 3 offen Mappe und ich schau durch und selektieren in irgend einer Tabelle in jede Mappe eine cell mit eine 1 drin. Dann ich kann die folgenderer code benutzen um die Summe diese 3 Nummern zu kriegen (Ich habs getested und es gibt ja 3 zurück), oder, zB. Die spalte Index von irgend einer. Es ist egal in welcher Mappe die code geschrieben ist und dieses Mappe muss nicht unbedingt aktivieret wurden!!

Code:
[B]Sub WindowsZuLetzteActiveCellDeutsch()
[/B] [COLOR=#008000]
[B]' So veile aktive cells da man will, und referenzieren sie[/B]
[B]' zB finde die Summe die 3 werte[/B][/COLOR]
[B]Dim x As Double[/B]
[B]Let x = Windows("Mappe1").ActiveCell.Value _[/B]
[B]+ Windows("Mappe2").ActiveCell.Value _[/B]
[B]+ Windows("Mappe3").ActiveCell.Value[/B]
 
[B]'[COLOR=#008000]   krieg eine Eigenschaft von irgend einer WindowsActiveCell[/COLOR][/B]
[B]Dim y As Integer[/B]
[B]Let y = Windows("Mappe1").ActiveCell.Column[/B]
 
[B]End Sub[/B]

. Ihrer Punkt das ich soll “ nicht die. Anwendungsobjekt in der Mitte des Objektpfad “. Das verstehe ich noch nicht ganz, - das hab ich auch diskutieret in die über genannt Link/ Thread. Schauern sie mal auch meine und Andrew Poulsom’s Kommentar dazu in die Englisch Version von diese thread/ Link / Thread http://www.mrexcel.com/forum/excel-...workbooks-windows-oop-method.html#post3818451 Kurz gesagt ich habe die Eindruck das VBA ist doch keine Objekt orientiert spräche.. nur etwas sehr ähnliches aussehender!?!?


Have a Wonder-Schön Day
Alan
 
Upvote 0
There is only one activecell per window. And normally you have a window for each open workbook. (This is not always the case - you might have a hidden workbook which will not have any associated windows.) My point was that if you have only one window for a particular workbook and you have two hundred worksheets, you will only have access to the active cell in that one window. If you wanted to be able to isolate the active cell on each worksheet, you would need to open a window for each worksheet and active a different sheet in each window. In the above example that would mean opening two hundred windows.


And while we are on the subject, using the ACTIVECELL object in VBA is usually a recipe for disaster. It is an extremely weak programming solution and should only be used when absolutely necessary.


Es gibt nur eine Active pro Fenster. Und normalerweise Sie haben ein Fenster für jeden geöffneten Arbeitsmappe. (Dies ist nicht immer der Fall -. Sie vielleicht eine versteckte Arbeitsmappe, die nicht haben, werden alle zugehörigen Fenster haben) Mein Punkt war, dass, wenn Sie nur ein Fenster für eine bestimmte Arbeitsmappe, und Sie zweihundert Arbeitsblätter haben, werden Sie nur Zugriff auf die aktive Zelle in diesem einen Fenster. Wenn Sie in der Lage, die aktive Zelle auf jedem Arbeitsblatt isolieren wollten, würden Sie brauchen, um ein Fenster für jedes Arbeitsblatt und aktiv ein anderes Blatt in jedem Fenster zu öffnen. Im obigen Beispiel würde das bedeuten, das Öffnen zweihundert Fenstern.


Und während wir auf das Thema, mit dem ActiveObjekt in VBA ist in der Regel ein Rezept für eine Katastrophe. Es ist eine extrem schwache Programmierlösung und sollte nur wenn unbedingt notwendig, verwendet werden.
 
Upvote 0
Hello again!
It’s probably down to my lack of experience and I do not know what I’m talking about…. But I seem to have only one window and as many worksheets as I want..(They shown in a long list at the bottom of my screen and a worksheet becomes “active,” that is to say I can see it when I click down there on the wanted worksheet name. All the other worksheets seem to be there (But I just don’t see them) and they all seem to have an active cell which I can access from anywhere using the code I described!?

.. Having said that, I’m sure you have a lot more experience than me and maybe I am just having “beginners luck” and a catastrophe is waiting around the corner. So I’ll start putting some effort in using another solution without using ActiveCell. (It’s a shame as it appears to work super for me)
Thanks for giving me the benefit of your experience, I appreciate it and as I said will make a good note of your warning!!.


P.s For the first time in my life I just played around with the frame of my (one) window... And now I can see all of my open workbooks at once. (I only noticed this because I am using a very big Telly at the moment as my display, otherwise I wouldn’t have been able to see them all). Only one active cell is to be seen which ties up with your “ There is only one activecell per window “ but my code still work, so clearly my code is referencing the last activated cell from every workbook open.


..........................................................
Alan

Hi nochmal!
Wahrscheinlisch wegen meine wenig Erfahrung schreib ich lauter Blödsinn.. Aber.. bei mir scheint als ob ich nur eine Window offen haben und so viele Workbooks wie ich will darin. (Da unter ist eine Liste von alle das “da” sind, bzw. Offen. Beim ein klicken drauf irgendeiner, erscheint es und ich kann es sehen. Aber ich denke die anderer sind ja auch da, und schein noch eine alle eine active cell zu haben und die kann ich alle angreifen wie ich will mit die Methoden ich geschrieben habe??

Aber das gesagt sie haben bestimmt mehr Ahnung als ich. Evtl. ich habe „Anfängers gluck“ und wie sie sagen es erwartet mir eine Katastrophe um di Ecke. Dann ich wäre mich kümmern an anderer Methode außer die activecell. (Schade es funktionieret Einbahn frei bei mir)
Danke das sie mir die Vorteil ihrer Erfahrung geben, habe - das schätz ich viel, und wie gesagt ich wäre gut bemerken ihrer Warnung!!
Alan

P.s. gerade habe ich mit die (eine) Windows rahmen das erste Mal überhaupt in meine leben gespeilte. Ich kann jetzt sogar schaffen alles die Workbooks gleich zu sehen.. in die selber Window!!! (Ich bemützt gerade eine sehr Groß fernsehen als Bildschirm, sonst wegen Platz Mängel hat es mir ja bis jetzt nicht aufgefallen!!!). Da ist ja nur einer cell aktivieret was stimmt mit ihren „ Es gibt nur eine Active pro Fenster „ Allerdings meine Code noch funktionieret. Also es greift an die letzte aktiviert cell von jede Offen Workbook.
 
Upvote 0
I am beginning to think that perhaps you do not know that you can open more than one window per workbook? On the VIEW tab, you can click New Window to open a second (or third, or fourth,...) window that shows the same workbook.

View Tab - Open New Window.png

You can then change the active worksheet in these windows. This allows you to view multiple worksheets in the same workbook. And each of these windows would have an ActiveCell property. If you did not understand this, then you may want to read my earlier posts again, taking this new information into consideration.


Ich fange an zu denken, dass Sie vielleicht nicht wissen, dass Sie mehr als ein Fenster pro Arbeitsmappe öffnen? Auf der Registerkarte Ansicht, klicken Sie auf Neues Fenster, um eine zweite (oder dritte oder vierte, ...) Fenster, die den gleichen Arbeitsmappe zeigt öffnen. Sie können dann das aktive Arbeitsblatt in diesen Fenstern. Damit können Sie mehrere Arbeitsblätter in derselben Arbeitsmappe anzuzeigen. Und jedem dieser Fenster wäre eine ActiveCell-Eigenschaft. Wenn Sie verstanden das nicht, dann möchten Sie vielleicht auf meine früheren Beiträge wieder zu lesen, wobei diese neuen Informationen in Betracht.
 
Upvote 0
Hi,

… I just tried what you said. You’re right I did not know that you could do that!! I am able to do and see exactly what you said. And I think I understand, so I just learnt something useful, thanks.
. Nevertheless, by simply opening many files one after the other I can get to see exactly the same except that instead of having lots worksheets open from the same workbook (and visible), I now have lots of workbooks open ( and visible) . (And each of these windows has an ActiveCell, that is to say The active cell is that which was active when I last clicked on / in the workbook.) It doesn’t seem to matter whether I have a sheet or a workbook in the Window.
. I will have a fresh read of everything you sent with a clear head tomorrow as it is late here now, but I think I understand everything. In the other forums I have explained that because of the way I am using the Activecell, it should rather have the name “LastActivatedCellThere” !!

http://www.mrexcel.com/forum/genera...nce%85-o00o-%60-_-%60-o00o-oop-hierarchy.html

Hi
….Ich habe ja gerade was sie gesagt habe ausprobieret. Sie haben recht ich wusste nicht das man konnte sowas machen!!. Und ich denke auch ich verstehe was sie meinen. Dann hab ich echt was neue gelernt, danke!!
. Trotzdem wenn ich einfach mehrerer Mappe offen, eine nach die andrerer, ich kann genau dieselbe sehen außer das statt mehrere Tabelle von die selber Mappe, ich hab jetzt mehrerer Mappe!!. Und die habe ja alles eine ActiveCell, bzw. die ActiveCell ist die das es war die letztemal das ich da drin geklickt habe.
. Ich schaumal alles sie mir geschickt habe nochmal durch morgen mit eine frische kopf, weil es ja spät hier ist, aber ich denke ich hab alles verstanden. In die anderer Forums Ich habe ja gesagt das so wie ich die Activecell benutzen, es sollte besser “CelldieletztermalDaActiveWar” genannt (wurden gewesen ?!?!??)

http://www.mrexcel.com/forum/genera...nce%85-o00o-%60-_-%60-o00o-oop-hierarchy.html
 
Upvote 0
Hallo,
. Ich denke ich krieg es ja langsam auf die Reihe!!I (Ich hab ja alles etwa durcheinander gebracht weil ich hab die Worte Workbooks und worksheets etwas willkürlich umgetauscht ( Das ist einfach weile ich typisch nur die erste Tabelle benutzen und damit sehe die erste Tabelle (Deswegen auch habe ich vergessen es in Code manchmal zu schreiben weil ich ja vergessen habe das es mehr als 1 gab/ gibt ) ) ) …. Sorry!!


. Ich habe nochmal alle die Info von Ihnen Alan Poulsom und der andere Threads wo es thematisieret ist gelesen

http://www.mrexcel.com/forum/excel-...workbooks-windows-oop-method.html#post3818273

http://www.mrexcel.com/forum/genera...nce%85-o00o-%60-_-%60-o00o-oop-hierarchy.html

. Ich Versuches eine letzter mal es zusammenzufassen um in meine kopf klar zu kriegen!!
. Ich habe ja 2 dinge (oder „Objekten!?“) etwa durscheinander gebracht / getauscht willkürlich

. 1) Application.ActiveCell und 2) Windows(item).ActiveCell

. Diese zwei dinge (Objekts) sind ähnlich. Sie haben ja die selber Funktionen und Eigenschaften. Aber es gibt wichtig unterscheiden

. 1) Für Application.ActiveCell gibt’s nur einer. Das ist die gerade selektierte oder „aktivieret“ cell oder andreres gesagt die „was ich sehe aufs Bildschirm der gezeigt ist in eine **** schwarz rahmen“ Weil es nur einer gibt, man braucht nicht viele code vor es zu schreiben um es zu qualifizieren, und es reicht meist voll aus so zu schreib ActiveCell. Usw. Viele anderer Objekten darf/ kann diese benutzen bzw. sie haben es ja als eine unter Objekt und man kriegt es gelistet beim rein Typen nach die Objekt eine Punkt . . (Das macht die Definitionen das VBA ist eine Hierarchien OOP etwas fraglisch, da man kann mit diese so zu sagen zurück üben in die Hierarchie gehen damit !! ??)

. 2) Etwas wichtig das ich verpasst habe, ist das ich kann ja viele Windows gleich zeitig offen haben und kann sogar sie alle (oder Teil davon mindestens) sehen (wenn meine Bildschirm groß genug ist!!)). Ich darf in jede fenster 1 Dinge haben. Das kann viele von die selber Tabelle von eine Mappe, oder viele verschiedener Tabelle von die selber Mappe oder irgendeiner Tabelle von irgendeiner Mappe. (Und wahrscheinlich noch mehrerer Sachen die ich noch nicht weise!!)
Genau oder „legal“ gesagt einer Tabelle oder Mappe hat keine ActiveCell, bzw. es wäre nicht zu ihnen angeboten wenn sie schreiben Workbooks( ). Oder worksheets( ).

. Aber in die Realität sie können „quasi“ eine haben, zB wie folgenderer:- (nur zum Spaß, nenn en wir das die AlanActivecell) Zum Beispiele Sage mal eben ich habe 200 Windows offen. Ich kann sehen (mindestens einer teil) von alle. Ich klick durch und selektieren in jede die cell die ich als die AlanActiveCell haben wollen. (bzw. die das ich angreifen und benutzen wollen) beim anklicken an die cell. . Zum Schluss ist ja nur eine cell selektieret, bzw. nur einer ist gezeigt in eine **** schwarz rahmen. Das ist ja die eine Application.Activecell. Aber ich habe 200 AlanActiveCells. Ich kann ja alle die gleicher Eigenschaft und Funktionen kriegen und benutzen von alle die AlanActivecells als beim mit die einziger application.Acivecel Das Kann ich mit code kriegen wie
( ZB. Für die erste cell das ich selektiert ):-

Code:
CellValueAlanActive1 = Windows(200).ActiveCell.Value
[COLOR=#008000]'  Or[/COLOR]
CellValueAlanActive1 = Windows.Item(200).ActiveCell.Value
[COLOR=#008000]'   Or[/COLOR]
CellValueAlanActive1 = Windows("WorkbookWorksheet_­Ersten").ActiveCell.Value
[COLOR=#008000]'   Or[/COLOR]
NameWorkbook1 = "WorkbookWorksheet_Ersten"
[COLOR=#008000]'     Or[/COLOR]
CellValueAlanActive1 = Windows(NameWorkbook1).ActiveCell.Value

[COLOR=#008000]'   etc... etc....   [/COLOR]
I kann das oder ähnliches tun für die anderer 1-199 (windows/workbook/worksheets oder was immer sie sind oder man sie nennen will!!)

. Also VBA ist nicht wirklisch OOP und man kann „quasi“ so viel aktiviert cells das man gleich zeitig haben will (gewesen sein!?)
.. Sorry aber ich bin eine alte Praktischer Physiker, und Arbeit nach dem Motto wenn ich sehe es und es funktionieret dann es existieret und ich kann es bemützten für /evtl einziger artig!) Losung!!. Dann Kummer mich dran später die Theorie das sagt es geht nett!!. Aber, wichtig, ich bin ja dankbar von die Vorteil ihren Erfahrung und bemerkt habe ihren Warnung nochmal. Dann suche ich noch bei Gelegenheit eine alternative Methode!

Alan
Doc.AElstein

P.s. Ich benutze Excel 2007 und 2010 „in“ WINDOWS XP und Vista.
. Typisch bemützt ich die erweiterter Desktop Optionen. Ich habe dann zwei Bildschirm gleich. Damit habe die VBA Entwicklung window und andere zeug genau vor mir auf meine Notebook Bildschirm und die Excel window auf eine groß fernsehe die auf die Wand hangt.

…………………………………………………………………..

Hello,
. I think I‘ve just about „got it“ now ! (I may have confused the issue a bit as I was mixing up Workbooks and Worksheets. ( That’s just because I tend just to use only the first sheet… so wot I always saw was “the” sheet in a workbook, so I may have used the term workbook or worksheet when I meant worksheet or workbook, (and I forgot to include the Worksheet sometimes as I forgot there could be more than 1 ) ) ) …. Sorry!!

. I’ve read again all your info, and that from Andrew Poulsom and all the other info given to me in the other forums

http://www.mrexcel.com/forum/excel-...workbooks-windows-oop-method.html#post3818273

http://www.mrexcel.com/forum/genera...nce%85-o00o-%60-_-%60-o00o-oop-hierarchy.html

. I’ll try to get it clear a last time in my head and summaries wot I’ve learnt as follows:-
. I was confusing 2 things ( that is to say 2 “Objects” !? )

. 1) Application.ActiveCell and 2) Windows(item).ActiveCell

. These two things (Objects) are similar. They have the same Properties and Functions but there are some important differences.

. 1) For Application.Active Cell there is only one. That is whichever cell is currently selected, or “activated” or “the cell wot I see on my screen highlighted in a thick black frame”. Because there is only one, you do not need to include a lot of qualifying code or path Info before it. In most cases something like x = ActiveCell. Etc. is good enough A lot of objects “have it” as one of their Functions or under objects and can call it with .Activecell (This make the definition of VBA as a hierarchical OOP a bit suspect, because you can use it to effectively go “backwards” .. or “up the hierarchy!” !!??)

. 2) An important point which I missed is that I can have lots of windows open at once (and even see them all at once (If I have a big enough Telly as a screen !!) ). I can have 1 item in each Window. That can be lots of the same sheet from a workbook or lots of different sheets from the same workbook or any sheets from any workbook, (and probably lots of other stuff I don’t know about yet!)
Technically speaking a Workbook and a worksheet doesn’t have an active cell, that is to say you won’t get it offered by typing Workbooks( ). Or worksheets( ).
. But really you can sort of have one. (For the sake of argument we’ll call it the AlanActivecell) For example let’s say I have 200 windows open. I can see (at least a bit!) of all of them. I go through every one and decide wot I want to be the AlanActiveCell (that is to say the one I want to access and use) by clicking on it. When I’ve finished I only see 1 cell in a box highlighted with a thick black frame.. That is the one and only Application.Activecell. But I have 200 AlanActiveCells. I can get all the same properties and use all the functions from any of the AlanActivecells as I can from the one and only application.Acivecell. I can do this with code such as (for example the first cell that I selected)

Code:
CellValueAlanActive1 = Windows(200).ActiveCell.Value
[COLOR=#008000]'  Or[/COLOR]
CellValueAlanActive1 = Windows.Item(200).ActiveCell.Value
[COLOR=#008000]'   Or[/COLOR]
CellValueAlanActive1 = Windows("WorkbookWorksheet_­FirstOne").ActiveCell.Value
[COLOR=#008000]'   Or[/COLOR]
NameWorkbook1 = "WorkbookWorksheet_FirstOne"
[COLOR=#008000]'     Or[/COLOR]
CellValueAlanActive1 = Windows(NameWorkbook1).ActiveCell.Value

[COLOR=#008000]'   etc... etc....[/COLOR]
I can repeat the above for the other 199 - 1 (windows/workbook/worksheets or whatever they are or whatever you want to call them)

. So really VBA isn’t OOP and you can have as many active cells as you want.
.. Sorry but I’M an old Practical Physicist and I work along the lines that if it works consistently then it exist and I’ll use it for (possibly novel) Solutions - I’ll worry about the theory that tells me it doesn’t exist o work later!!
(Having said that I will take note of your experienced advice and I’ll look for a better or “legal” way as well as I go along)

Alan
Doc.AElstein




P.s. I use Excel 2007 or 2010 “in” WINDOWS XP or Vista
. Usually I use the monitor option that allows me to have 2 screens at once. I have the VBA development window and other stuff right in front of me on my Notebook screen and the big Excel Workbook Window with lots in it on a big Telly screen stuck on the wall

………………………………………………………………


 
Last edited:
Upvote 0
In the next post I am going to post some code that hopefully will help you understand the differences between the various window, workbook and worksheet objects. You may need to step through the code using the F8 key several times to understand what's happening.


Im nächsten Beitrag werde ich einige Code, der hoffentlich helfen, die Unterschiede zwischen den verschiedenen Fenster, Arbeitsmappe und Arbeitsblatt Objekte zu verstehen posten. Möglicherweise müssen Sie den Code mit Hilfe der F8-Taste mehrmals zu verstehen, was passiert Schritt.
 
Upvote 0

Forum statistics

Threads
1,215,378
Messages
6,124,603
Members
449,174
Latest member
ExcelfromGermany

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top