Page 10 of 17 FirstFirst ... 89101112 ... LastLast
Results 91 to 100 of 162

Thread: Test Video,YouTube, Video making and editing, etc. coupled to excelfox (OBS)

  1. #91
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this Post
    http://www.excelfox.com/forum/showth...0771#post10771

    Using Excel 2007 32 bit
    Row\Col
    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    1
    Original Original Original Original Original Original Test Output Test Output Test Output Test Output Test Output NEW NEW NEW NEW NEW NEW
    2
    Assembly #: Assembly Name: Assembly #: Assembly Name:
    3
    Qty Per Ref/Designator Description Customer PN Internal PN Manufacture PN Qty Per Ref/Designator Description Customer PN Internal PN Manufacture PN
    4
    1
    Nu Torque ABC
    456
    456
    ABC < > 13456
    1
    Nu Torque
    13456
    456
    456
    5
    1
    Blu Origin Spaceship
    457
    457
    1
    Blu Origin Spaceship
    457
    457
    6
    2
    Jet Blue21 ABC
    458
    458
    2
    New: Jet Blue23 ABC New: DEF New: DEF
    2
    Jet Blue23 ABC DEF DEF
    7
    3
    EXCELL123
    123
    ABC ABC
    3
    EXCELL123
    123
    ABC ABC
    8
    3
    Toyota Supra
    460
    460
    3
    Toyota Supra
    460
    460
    9
    2
    Emirate ABC12345
    461
    461
    2
    Emirate ABC12345
    461
    461
    10
    1
    Angel ABC12346
    462
    462
    MISSING: 1 MISSING: Angel MISSING: ABC12346 MISSING: 462 MISSING: 462
    2
    Jet Blue21 ABC
    458
    458
    Worksheet: Result Wanted




    Using Excel 2007 32 bit
    1
    Nu Torque ABC
    456
    456
    ABC < > 13456
    1
    Nu Torque
    13456
    456
    456
    1
    Blu Origin Spaceship
    457
    457
    1
    Blu Origin Spaceship
    457
    457
    2
    Jet Blue21 ABC
    458
    458
    2
    New: Jet Blue23 ABC New: DEF New: DEF
    2
    Jet Blue23 ABC DEF DEF
    3
    EXCELL123
    123
    ABC ABC
    3
    EXCELL123
    123
    ABC ABC
    3
    Toyota Supra
    460
    460
    3
    Toyota Supra
    460
    460
    2
    Emirate ABC12345
    461
    461
    2
    Emirate ABC12345
    461
    461
    1
    Angel ABC12346
    462
    462
    MISSING: 1 MISSING: Angel MISSING: ABC12346 MISSING: 462 MISSING: 462
    2
    Jet Blue21 ABC
    458
    458
    Worksheet: Result Wanted

  2. #92
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    Loop through closed workbooks without opening them

    Code for Yasser, here: http://www.eileenslounge.com/viewtop...241152#p241148



    Code:
    Option Explicit
    Sub SUMfromD14inClsdWkBksInFolder() ' Loop through closed workbooks without opening them '    http://www.eileenslounge.com/viewtopic.php?f=30&t=31150&p=241152#p241152
    ' Use Dir function with wildcards in full path and name search string to find file names you want
    Dim FileName As String:
     Let FileName = Dir("C:\Users\Elston\Desktop\YassersFolder\*record*", vbNormal) ' The Dir function uased the first time here, it will find the first file with "record" in its file name in the folder , "YassersFolder". If it does not find one,  it will return "". If it finds one, then variable FileName will be given its name, ( just the name, not the entire file path and name)
    'Do do Looping while you find the file names you want =========
        Do While Not FileName = "" ' Dir Function will return "" if it finds no new File names of the ones looking for. If it does find a File name, then use that filename in the closed workbook reference which you put in a spare cell, for example, A1
         Let ThisWorkbook.Worksheets.Item(1).Range("A1").Value = "=" & "'" & "C:\Users\Elston\Desktop\YassersFolder\" & "[" & FileName & "]Tabelle1'!$D$14"
        Dim SomeTotal As Double ' A variable to hold the Sum total so far
         Let SomeTotal = SomeTotal + ThisWorkbook.Worksheets.Item(1).Range("A1").Value
         Let FileName = Dir ' an unqualified Dir will look again using the last search criteria, so the first time this line is used, Dir Function  will try to find a second file with the string part "record" in its file name
        Loop '  do while you find the file names you want ==========
    Let ThisWorkbook.Worksheets.Item(1).Range("A10").Value = SomeTotal
    End Sub

  3. #93
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    Named Ranges scope defines the default path used for a named range, nothing else

    Codes to support this
    https://www.thespreadsheetguru.com/b...ent-4189507335

    ....

    The main demo code is Sub NamedRangeScopes() , but that Calls the others, so copy them all to the same code module , and then run the main demo code, Sub NamedRangeScopes()

    Code:
    Sub NamedRangeScopes()
    10    Call FukOffNames
    20    Call getWbNames
    30   Rem 1 Add 3 named ranges, 1(i) '_-in the Workbooks name object collection, and 1(ii) in the first worksheet name object collection and 1(iii) '_-in the second worksheet name object collection
    40   '1(i) Add a Workbook names object in the Workbook name object collection of this workbook
    50    ThisWorkbook.Names.Add Name:="Name1", RefersTo:=ThisWorkbook.Worksheets.Item(1).Range("A1")   '_-in the Workbooks name object collection
    60    'The form above is like   ThisWorkbook.Names.Add Name:="Name1", RefersTo:=Worksheets(Sheet1).Range("A1")
    70   '1(ii) Add a name object in the first worksheet's name object collection
    80    ThisWorkbook.Worksheets.Item(1).Names.Add Name:="Name1", RefersTo:=ThisWorkbook.Worksheets.Item(1).Range("A1")  '_-in the first worksheet name object collection
    90    'The form above is like   Worksheets("Sheet1).Names.Add Name:="Name1"  ,    RefersTo:=Sheet1.Range("A1")
    100  '1(iii) Add a name object in the second worksheet's name object collection
    110   ThisWorkbook.Worksheets.Item(2).Names.Add Name:="Name2", RefersTo:=ThisWorkbook.Worksheets.Item(2).Range("A1")  '_-in the second worksheet name object collection
    120   'The form above is like   Worksheets("Sheet2).Names.Add Name:="Name2"  ,    RefersTo:=Sheet2.Range("A1")
    130  Rem 2 Change the string name of a named range
    140   Call GetChaNameObjects(140) ' Check out Info for all Name objects
    150  '2a) Use Workbook names objects to Change the worksheet names object name that has the same name as the workbook names object name, change it twice, first using the workbook names object collection and then the worksheet names object collection
    160   Let ThisWorkbook.Names(ThisWorkbook.Worksheets.Item(1).Name & "!" & "Name1").Name = "Name1_1"
    170   '       The form above is like             ThisWorkbook.Names("Sheet1!Name").Name = "Name1_1"
    180   Call GetChaNameObjects(180)
    190   Let ThisWorkbook.Worksheets.Item(1).Names(ThisWorkbook.Worksheets.Item(1).Name & "!" & "Name1_1").Name = "Name1_2"
    200   Call GetChaNameObjects(200)
    210   Let ThisWorkbook.Worksheets.Item(1).Names("Name1_2").Name = "Name1_3"
    220   Call GetChaNameObjects(220)
    230  '2b) use a Worksheet's (in this example the second worksheet's) name objects to Change the second worksheet's names object, ( we gave it "Name2", but Excel adds a bit so it looks like  Sheet2!Name2" which you can get from a VBA code line like  ThisWorkbook.Worksheets.Item(2).Name & "!" & "Name2"   I do this just in case your second worksheet has a tab name other than  Sheet2
    240   Let ThisWorkbook.Worksheets.Item(2).Names("Name2").Name = "Name2_2"
    250   ' Note: you could have equally done this:     Let ThisWorkbook.Worksheets.Item(2).Names(ThisWorkbook.Worksheets.Item(2).Name & "!" & "Name2").Name = "Name2_2"  , which is like   Let ThisWorkbook.Worksheets.Item(2).Names("Sheet2!Name2").Name = "Name2_2"
    260   Call GetChaNameObjects(260)
    270  Rem 3 Change the string name of a named range, for example the one in the second worksheet names collection whichg we just renamed to "Name2_2" ,(which Excel holds as like  "Sheet2!Name2_2")
    280  '3a) Use Workbook names objects
    290   Let ThisWorkbook.Names(ThisWorkbook.Worksheets.Item(2).Name & "!" & "Name2_2").RefersTo = ThisWorkbook.Worksheets.Item(2).Range("Z123")
    300   Call GetChaNameObjects(300)
    310  '3b) Use the second worksheets's  names objects
    320   Let ThisWorkbook.Worksheets.Item(2).Names("Name2_2").RefersTo = ThisWorkbook.Worksheets.Item(2).Range("X23")
    330   Call GetChaNameObjects(330)
    End Sub
    Code:
    Sub FukOffNames()
    Dim Nme As Name
         For Each Nme In ThisWorkbook.Names
          Nme.Delete
         Next Nme
    End Sub
    Code:
    Sub GetChaNameObjects(ByVal CodLn As Long)
    Dim Nme As Name, strOut As String
    ' Name objects belonging in Workbook Names Colection (Workbooks scope)
         For Each Nme In ThisWorkbook.Names
            If InStr(1, Nme.Name, "!", vbBinaryCompare) > 0 Then ' we will see that a name for a worksheet scope, has an extra bit added onto the name we gave it which includes a "!"
             Let strOut = strOut & "Name object Name is  """ & Nme.Name & """ (you gave """ & Mid(Nme.Name, 1 + InStr(1, Nme.Name, "!", vbBinaryCompare)) & """)" & vbCrLf & "It has worksheet scope and" & vbCrLf & "it refers to range  """ & Nme.RefersTo & """" & vbCrLf & vbCrLf & vbCrLf
            Else ' we will see that a name for a workbook scope, remains just as we gave it
             Let strOut = strOut & "Name object Name is  """ & Nme.Name & """ (the same as you gave)" & vbCrLf & "It has workbook scope and" & vbCrLf & "it refers to range  """ & Nme.RefersTo & """" & vbCrLf & vbCrLf & vbCrLf
            End If
        Next Nme
     MsgBox prompt:="Workbook names situation at Code Line " & CodLn & vbCrLf & vbCrLf & strOut, Title:="Name objects in Workbook """ & ThisWorkbook.Name & """ Names Colection are:-": Debug.Print "Name objects in Workbook """ & ThisWorkbook.Name & """ Names Colection are:-" & vbCr & strOut
    ' Name objects belonging in Workbooks Names Colection (Worksheets scope)
    Dim Ws As Worksheet: Let strOut = ""
        For Each Ws In ThisWorkbook.Worksheets
            For Each Nme In Ws.Names
             Let strOut = strOut & "Name object name is  """ & Nme.Name & """ (you gave """ & Mid(Nme.Name, 1 + InStr(1, Nme.Name, "!", vbBinaryCompare)) & """)" & vbCrLf & "It has worksheets scope and" & vbCrLf & "it belongs to the Names collection of worksheet """ & Ws.Name & """" & vbCrLf & "and it refers to range  """ & Nme.RefersTo & """" & vbCrLf & vbCrLf
            Next Nme
        Next Ws
     MsgBox prompt:="Worksheets names situation at Code Line " & CodLn & vbCrLf & vbCrLf & strOut, Title:="Name objects in all the worksheets Names Colections are:-": Debug.Print "Name objects in all the worksheets Names Colections are:-" & strOut
    End Sub
    Code:
    Sub getWbNames()
    Dim Nme As Name, Cnt As Long
        For Each Nme In ThisWorkbook.Names
         Let Cnt = Cnt + 1
        Dim strNames As String: Let strNames = strNames & Cnt & "   "
            If TypeOf Nme.Parent Is Worksheet Then '   https://stackoverflow.com/questions/8656793/progammatically-determine-if-a-named-range-is-scoped-to-a-workbook
             Let strNames = strNames & """" & Nme.Name & """  refers to the range ref  """ & Nme & """  and and can be referenced only from worksheet with tab Name  """ & Nme.Parent.Name & """ ( Worksheet Scope ). ( That worksheet is in the workbook  """ & Nme.Parent.Parent.Name & """  )" & vbCrLf & vbCrLf
            Else
             Let strNames = strNames & """" & Nme.Name & """  refers to the range ref  """ & Nme & """  and can be referenced from any sheet in the Workbook  """ & Nme.Parent.Name & """  ( Workbook Scope )" & vbCrLf & vbCrLf
            End If
        Next Nme
        If strNames = "" Then
         MsgBox prompt:="I don't think you have any Names at the moment luvy"
        Else
         MsgBox prompt:=strNames, Title:="Spreadsheet Named range objects in " & ThisWorkbook.Name & " are:-": Debug.Print strNames
        End If
    End Sub

  4. #94
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    Further Practice with using named ranges

    First main Demo code in support of this Thread:
    http://www.excelfox.com/forum/showth...-a-named-range
    Posts from approximately here:
    http://www.excelfox.com/forum/showth...814#post10814:



    Code:
    Sub FoxySingleCellNamedRanges()
    10   Rem -2 Range Info etc.
    20   Dim WbMain As Workbook, dataWb1xls As Workbook, dataWb2xlsx As Workbook
    30    Set WbMain = Workbooks("MasturFile.xlsm") 'Set WbMain = ThisWorkbook
    40    Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    50    Set dataWb1xls = Workbooks("Data1.xls")
    60    Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    70    Set dataWb2xlsx = Workbooks("Data2.xlsx")
    80 '
    90   Dim LisWkBkPath As String: Let LisWkBkPath = "=" & "'" & ThisWorkbook.Path & "\"
    100  '-2b) Some variables to hold a full reference string which we will use in places where we might need any of these variations for a cell reference  Sheet7!B5  [myWorkbook.xlsm] Sheet4!B5  'G:\Desktop\MyFolder\[DataFile.xlsx]Tabelle1'!B5   The last one is the form we hold in the variables. Excel and Excel VBA , usually has no issues if you use the full reference in situations where one of the shorter versions may have been sufficient. But on the other hand,  you may get unexpected problems if you used a shorter version , and Excel then  guesses wrongly  for the remaining part, which I believe it always adds internally, ( possibly at some compiling stage ) , before it uses it.
    110  Dim MBkTab1B5 As String ' To hold full string reference to B5 in Master Workbook
    120   Let MBkTab1B5 = "=" & "'" & ThisWorkbook.Path & "\" & "[" & "MasturFile.xlsm" & "]" & "Tabelle1" & "'" & "!" & "B5"
    130  Dim Dat1Tab1B5 As String ' B5 in data1 workbook
    140   Let Dat1Tab1B5 = "=" & "'" & ThisWorkbook.Path & "\" & "[" & "Data1.xls" & "]" & "Tabelle1" & "'" & "!" & "B5"
    150
    160  Rem -1 Error handler
    170   On Error GoTo ErrorHandlerCodeSection:
    180  GoTo PastErrorHandler
    190 ErrorHandlerCodeSection:
    200   MsgBox prompt:="Code errored at line  " & Erl & " , error was:" & vbCrLf & vbCrLf & Err.Number & "     " & Err.Description
    210   Debug.Print Err.Number & "     " & Err.Description
    220   Resume Next
    230 PastErrorHandler:
    240  Rem 0 Clean up
    250  Dim WkBk As Workbook
    260      For Each WkBk In Workbooks
    270       Call FukYaWkBkNames(WkBk)
    280       'Call GeTchaNms(280, WkBk)
    290      Next WkBk
    300   Workbooks("Data1.xls").Close savechanges:=True
    310   Workbooks("Data2.xlsx").Close savechanges:=True
    312  '0b) clear the entire data ranges in the first worksheet in the main workbook, both headers and data
    315   ThisWorkbook.Worksheets.Item(1).Range("B5:C12").ClearContents
    320  Rem _1) Data1 "Food" header
    330  '1a) Data1 cell Workbook Scoped to its workbook : Info needed for a range in that data file is held in the workbooks name objects collection object of that workbook
    340   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    350   Set dataWb1xls = Workbooks("Data1.xls") ' We need this open for the referred to range in the RefersTo:= range reference below
    360   dataWb1xls.Names.Add Name:="Dta1Foodheader", RefersTo:=Application.Range(Dat1Tab1B5) ' A personal preference of mine is , once again, to use a full reference. This time it is  in the Refers To range. This Refers To:= argument would never need the full file path reference, as the range referenced must be to a range in an open book. Never the less, as usual, VBA accepts the full reference
    370   Call GeTchaNms(370, dataWb1xls)
    380   dataWb1xls.Close savechanges:=True ' I don't need the workbook open for the next line to work, but I made Added a named range object so I must save the changes for the next line to work as that named range is referenced
    390   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "Data1.xls'!Dta1Foodheader" ' "Going" to Workbook  Data1.xls
    400   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "[Data1.xls]Tabelle4'!Dta1Foodheader" ' "Going" to any worksheet in  Data1.xls
    410  '1b) Data1 cell Worksheet Scoped to one of its worksheets: Info needed is held in the named objects object of its second worksheets
    420   Rem _1 Add some named ranges
    430   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    440   Set dataWb1xls = Workbooks("Data1.xls") ' We need this open for the referred to range in the RefersTo:= range reference below
    450   dataWb1xls.Worksheets.Item(2).Names.Add Name:="Ws2Dta1Foodheader", RefersTo:=Application.Range(Dat1Tab1B5)
    460   Call GeTchaNms(460, dataWb1xls)
    470   dataWb1xls.Close savechanges:=True ' I don't need the workbook open for the next line to work, but I made Added a named range object so I must save the changes for the next line to work as that named range is referenced
    480   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "[Data1.xls]Tabelle2'!Ws2Dta1Foodheader"
    490  '1b)(ii)
    500   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    510   Set dataWb1xls = Workbooks("Data1.xls") ' We need this open for the referred to range in the RefersTo:= range reference below
    520   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "[Data1.xls]Tabelle2'!Ws2Dta1Foodheader"
    530   dataWb1xls.Close savechanges:=False ' I made no changes intentionally , so save without changes in case I accidentally changed anything
    540  '1c) Data1 cell Workbook Scoped to a different (open) workbook : Info needed for a range in the data 1 file is held in the workbooks name objects collection object of that workbook, the main file in this case
    550   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    560   Set dataWb1xls = Workbooks("Data1.xls") ' We need this open for the referred to range in the RefersTo:= range reference below
    570   WbMain.Names.Add Name:="MainDta1Foodheader", RefersTo:=Application.Range(Dat1Tab1B5)
    580   dataWb1xls.Close savechanges:=False ' I had this open for the  Refers To:=  above, but I did not change anything, for example, this time i was not doing anything to any of its named range objects, so just iin case I accidentally changed anything I will close without saving any changes
    590   Call GeTchaNms(590, WbMain)
    600   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "MasturFile.xlsm'!MainDta1Foodheader" ' "Going" to Workbook  MasturFile.xlsm
    610   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "[MasturFile.xlsm]Tabelle4'!MainDta1Foodheader" ' "Going" to any worksheet in MasturFile.xlsm
    620  '1d) This is an attempt to get at the named range object in a roundabout sort of a way. Here the data 1 cell s scoped to the second data file, "Data2.xlsx" ( Workbooks scoped to workbook "Data2.xlsx" )
    630   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    640   Set dataWb1xls = Workbooks("Data1.xls")
    650   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    660   Set dataWb2xlsx = Workbooks("Data2.xlsx")
    670   dataWb2xlsx.Names.Add Name:="Dta2Dta1Foodheader", RefersTo:=Application.Range(Dat1Tab1B5)
    680   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "Data2.xlsx'!Dta2Dta1Foodheader" ' "Going" to Workbook  MasturFile.xlsm
    690   dataWb1xls.Close savechanges:=False ' I had this open for the  Refers To:=  above, but I did not change anything, for example, this time i was not doing anything to any of its named range objects, so just iin case I accidentally changed anything I will close without saving any changes
    700   dataWb2xlsx.Close savechanges:=True ' A name object was Added, so I have a change to save
    710   Let Application.Range(MBkTab1B5).Value = Application.Range(MBkTab1B5).Value ' I have done this here to "catch" the value put in, as it seems to vanish if I re enter the formula ??
    720  Rem 2 Experiments with named ranges in the LHS , like in Range("rngNamed") =
    730  '2a) scope to a data file
    740   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    750   Set dataWb2xlsx = Workbooks("Data2.xlsx") ' Open an arbritrary data file to use one if its names objects as the place to go to get the info about the named range
    760   dataWb2xlsx.Names.Add Name:="Dta2MainFoodheader", RefersTo:=Application.Range(MBkTab1B5)
    770   Call GeTchaNms(770, dataWb2xlsx)
    780   Let Application.Range(LisWkBkPath & "Data2.xlsx'!Dta2MainFoodheader").Value = LisWkBkPath & "Data1.xls'!Dta1Foodheader" ' LHS is going to workbook Data2.xlsx     RHS is "Going" to Workbook  Data1.xls
    790   dataWb2xlsx.Close savechanges:=True ' A name object was Added, so I have a change to save
    800   Let Application.Range(LisWkBkPath & "Data2.xlsx'!Dta2MainFoodheader").Value = LisWkBkPath & "Data1.xls'!Dta1Foodheader" ' LHS is going to workbook Data2.xlsx      RHS is "Going" to Workbook  Data1.xls
    810  '2b) Workbooks Scope to main workbook: Info for named range is in Name Objects collection of Main workbook
    820   WbMain.Names.Add Name:="MainFoodheader", RefersTo:=Application.Range(MBkTab1B5)
    830   Let Application.Range(LisWkBkPath & WbMain.Name & "'!MainFoodheader").Value = LisWkBkPath & "Data1.xls'!Dta1Foodheader" ' LHS is going to workbook Data2.xlsx      RHS is "Going" to Workbook  Data1.xls
    840   Call GeTchaNms(840, WbMain)
    850  Rem 3 Bring in Header "Suppliment" from data 2 workbook directly without named ranges
    860   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    870   Set dataWb2xlsx = Workbooks("Data2.xlsx") ' Needed for next line
    880   Let Application.Range("=" & "'" & WbMain.Path & "\" & "[" & WbMain.Name & "]" & WbMain.Worksheets.Item(1).Name & "'" & "!" & "B10").Value = "=" & "'" & dataWb2xlsx.Path & "\" & "[" & dataWb2xlsx.Name & "]" & dataWb2xlsx.Worksheets.Item(1).Name & "'" & "!" & "B10"
    890   dataWb2xlsx.Close savechanges:=False
    End Sub

  5. #95
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Second main Demo Code in support of this Thread:
    http://www.excelfox.com/forum/showth...-a-named-range
    For Posts from:
    http://www.excelfox.com/forum/showth...0819#post10819



    Code:
    Sub FoxyMultiCellNamedRanges()
    10   Rem -2 Range Info etc.
    20   Dim WbMain As Workbook, dataWb1xls As Workbook, dataWb2xlsx As Workbook
    30    Set WbMain = Workbooks("MasturFile.xlsm") 'Set WbMain = ThisWorkbook
    40    Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    50    Set dataWb1xls = Workbooks("Data1.xls")
    60    Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    70    Set dataWb2xlsx = Workbooks("Data2.xlsx")
    80   '
    90   Dim LisWkBkPath As String: Let LisWkBkPath = "=" & "'" & ThisWorkbook.Path & "\"
    100  '-2b) Some variables to hold a full reference string which we will use in places where we might need any of these variations for a cell reference  Sheet7!B5  [myWorkbook.xlsm] Sheet4!B5  'G:\Desktop\MyFolder\[DataFile.xlsx]Tabelle1'!B5   The last one is the form we hold in the variables. Excel and Excel VBA , usually has no issues if you use the full reference in situations where one of the shorter versions may have been sufficient. But on the other hand,  you may get unexpected problems if you used a shorter version , and Excel then  guesses wrongly  for the remaining part, which I believe it always adds internally, ( possibly at some compiling stage ) , before it uses it.
    110  Dim MBkTab1B5 As String ' To hold full string reference to B5 in Master Workbook
    120   Let MBkTab1B5 = "=" & "'" & ThisWorkbook.Path & "\" & "[" & "MasturFile.xlsm" & "]" & "Tabelle1" & "'" & "!" & "B5"
    130  Dim Dat1Tab1B5 As String ' B5 in data1 workbook
    140   Let Dat1Tab1B5 = "=" & "'" & ThisWorkbook.Path & "\" & "[" & "Data1.xls" & "]" & "Tabelle1" & "'" & "!" & "B5"
    150 '
    160  Rem -1 Error handler
    170   On Error GoTo ErrorHandlerCodeSection:
    180  GoTo PastErrorHandler
    190 ErrorHandlerCodeSection:
    200   MsgBox prompt:="Code errored at line  " & Erl & " , error was:" & vbCrLf & vbCrLf & Err.Number & "     " & Err.Description
    210   Debug.Print Err.Number & "     " & Err.Description
    220   Resume Next
    230 PastErrorHandler:
    240  Rem 0 Clean up
    250  '0a) remove any name objects made in last routine in the main file or the two data files
    260  Dim WkBk As Workbook
    270      For Each WkBk In Workbooks
    280       Call FukYaWkBkNames(WkBk)
    290       'Call GeTchaNms(280, WkBk)
    300      Next WkBk
    310   Workbooks("Data1.xls").Close savechanges:=True
    320   Workbooks("Data2.xlsx").Close savechanges:=True
    330  '0b) clear the entire data ranges in the first worksheet in the main workbook, both headers and data
    340   ThisWorkbook.Worksheets.Item(1).Range("B5:C12").ClearContents
    350  Rem _1) Data1 "Food" header
    360  '1a) Data1 cell Workbook Scoped to its workbook : Info needed for a range in that data file is held in the workbooks name objects collection object of that workbook
    370   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    380   Set dataWb1xls = Workbooks("Data1.xls") ' We need this open for the referred to range in the RefersTo:= range reference below
    390   dataWb1xls.Names.Add Name:="Dta1Foodheader", RefersTo:=Application.Range(Dat1Tab1B5) ' A personal preference of mine is , once again, to use a full reference. This time it is  in the Refers To range. This Refers To:= argument would never need the full file path reference, as the range referenced must be to a range in an open book. Never the less, as usual, VBA accepts the full reference
    400   dataWb1xls.Close savechanges:=True ' I don't need the workbook open for the next line to work, but I made Added a named range object so I must save the changes for the next line to work as that named range is referenced
    410   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "Data1.xls'!Dta1Foodheader" ' "Going" to Workbook  Data1.xls
    420   Let Application.Range(MBkTab1B5).Value = LisWkBkPath & "[Data1.xls]Tabelle4'!Dta1Foodheader" ' "Going" to any worksheet in  Data1.xls
    430  Rem 2 Experiments with named ranges in the LHS , like in Range("rngNamed") =
    440  '2b) Workbooks Scope to main workbook: Info for named range is in Name Objects collection of Main workbook
    450   WbMain.Names.Add Name:="MainFoodheader", RefersTo:=Application.Range(MBkTab1B5)
    460   Let Application.Range(LisWkBkPath & WbMain.Name & "'!MainFoodheader").Value = LisWkBkPath & "Data1.xls'!Dta1Foodheader" ' LHS is going to workbook Data2.xlsx      RHS is "Going" to Workbook  Data1.xls
    470  Rem 3 Bring in Header "Suppliment" from data 2 workbook directly without named ranges
    480   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    490   Set dataWb2xlsx = Workbooks("Data2.xlsx") ' Needed for next line
    500   Let Application.Range("=" & "'" & WbMain.Path & "\" & "[" & WbMain.Name & "]" & WbMain.Worksheets.Item(1).Name & "'" & "!" & "B10").Value = "=" & "'" & dataWb2xlsx.Path & "\" & "[" & dataWb2xlsx.Name & "]" & dataWb2xlsx.Worksheets.Item(1).Name & "'" & "!" & "B10"
    510  '3b) "Fixed vector" B11 into main workbook at B11
    520   Let Application.Range("=" & "'" & WbMain.Path & "\" & "[" & WbMain.Name & "]" & WbMain.Worksheets.Item(1).Name & "'" & "!" & "B11").Value = "=" & "'" & dataWb2xlsx.Path & "\" & "[" & dataWb2xlsx.Name & "]" & dataWb2xlsx.Worksheets.Item(1).Name & "'" & "!" & "B11"
    530  '3c) "Fixed vector" B11 into main workbook into  B11 C11 B12 and C12
    540   Let Application.Range("=" & "'" & WbMain.Path & "\" & "[" & WbMain.Name & "]" & WbMain.Worksheets.Item(1).Name & "'" & "!" & "B11:C12").Value = "=" & "'" & dataWb2xlsx.Path & "\" & "[" & dataWb2xlsx.Name & "]" & dataWb2xlsx.Worksheets.Item(1).Name & "'" & "!" & "B11"
    550   dataWb2xlsx.Close savechanges:=False
    560 '
    570   Application.Range("=" & "'" & WbMain.Path & "\" & "[" & WbMain.Name & "]" & WbMain.Worksheets.Item(1).Name & "'" & "!" & "B11:C12").ClearContents ' remove the data from the main file from data file 2 so as to do the same again using named ranges in the next code section, Rem 4
    580  Rem 4 named ranges for data ranges in data workbooks and main file
    590  '4a) Workbook to store name range object
    600  Dim WbNmeObjs As Workbook
    610   Workbooks.Open Filename:=ThisWorkbook.Path & "\StoredNamedRangeNameObjects.xls"
    620   Set WbNmeObjs = Workbooks("StoredNamedRangeNameObjects.xls")
    630   Call FukYaWkBkNames(WbNmeObjs)
    640   Call GeTchaNms(640, WbNmeObjs)
    650  '4b) named ranges for data in data range from data 1 workbook, "Data1.xls
    660   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    670   Set dataWb1xls = Workbooks("Data1.xls") ' We need this open for the referred to range in the RefersTo:= range reference below
    680   WbNmeObjs.Worksheets("DataFileNameObjects").Names.Add Name:="NmsObjDta1Data", RefersTo:=Application.Range("='" & ThisWorkbook.Path & "\[Data1.xls]Tabelle1'!B6:C7")
    690   Call GeTchaNms(690, WbNmeObjs)
    700  '4c) named ranges for data in data range from data 2 workbook, "Data2.xlsx
    710   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    720   Set dataWb2xlsx = Workbooks("Data2.xlsx") ' We need this open for the referred to range in the RefersTo:= range reference below
    730   WbNmeObjs.Worksheets("DataFileNameObjects").Names.Add Name:="NmsObjDta2Data", RefersTo:=Application.Range("='" & ThisWorkbook.Path & "\[Data2.xlsx]Tabelle1'!B11:C12")
    740   Call GeTchaNms(740, WbNmeObjs)
    750  '4d) named ranges for data import ranges in main workbook, ( This workbook )
    760  '4d(i) data from Data 1 file import range in main book
    770   WbNmeObjs.Worksheets("MainFileNameObjects").Names.Add Name:="NmsObjDta1Import", RefersTo:=Application.Range("='" & ThisWorkbook.Path & "\[MasturFile.xlsm]Tabelle1'!B6:C7")
    780  '4d(ii) data from Data 2 file import range in main book
    790   WbNmeObjs.Worksheets("MainFileNameObjects").Names.Add Name:="NmsObjDta2Import", RefersTo:=Application.Range("='" & ThisWorkbook.Path & "\[MasturFile.xlsm]Tabelle1'!B11:C12")
    800  Call GeTchaNms(800, WbNmeObjs)
    810  ' Close data books - I don't need them open to get at their named range data or their named range data
    820   dataWb1xls.Close savechanges:=False ' I needed the workbook open for the referes to range reference and the  GeTchaNms( )  to work, but i added no names to it, so I did not intentiionally make any changes, so I will close with changes false in case I acidentally changed anything
    830   dataWb2xlsx.Close savechanges:=False ' I needed the workbook open for the referes to range reference and the  GeTchaNms( )  to work, but i added no names to it, so I did not intentiionally make any changes, so I will close with changes false in case I acidentally changed anything
    840  Rem 5 Using the Added data named ranges to bring in data from the data files into the main workbook
    850  '5a) Food data data range ( B6:C7 in main File and B6:C7 in data 1 file )
    860   Let Application.Range("='" & ThisWorkbook.Path & "\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta1Import").FormulaArray = "='" & ThisWorkbook.Path & "\[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta1Data"
    870  '5a)(ii) As file "StoredNamedRangeNameObjects.xls" is open we can also use
    880   Let Application.Range("='[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta1Import").FormulaArray = "='[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta1Data"
    890  '5b) Food data data range ( B11:C12 in main File and B11:C12 in data 2 file )
    900   Let Application.Range("='" & ThisWorkbook.Path & "\[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta2Import").FormulaArray = "='" & ThisWorkbook.Path & "\[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta2Data"
    910  '5b)(ii) As file "StoredNamedRangeNameObjects.xls" is open we can also use
    920   Let Application.Range("='[StoredNamedRangeNameObjects.xls]MainFileNameObjects'!NmsObjDta2Import").FormulaArray = "='[StoredNamedRangeNameObjects.xls]DataFileNameObjects'!NmsObjDta2Data"
    930  '5c)
    940   WbNmeObjs.Close savechanges:=True ' Save the named range info on closing
    950  '5d) Optional Change all formulas to their values
    960   Let WbMain.Worksheets.Item(1).UsedRange.Value = WbMain.Worksheets.Item(1).UsedRange.Value
    970  Rem 6 Final check of all named ranges
    980  '6a) Open all workbooks so as to access Named range objects in them
    990   Workbooks.Open Filename:=ThisWorkbook.Path & "\Data1.xls"
    1000   Set dataWb1xls = Workbooks("Data1.xls")
    1010  Workbooks.Open Filename:=ThisWorkbook.Path & "\Data2.xlsx"
    1020  Set dataWb2xlsx = Workbooks("Data2.xlsx")
    1030   Workbooks.Open Filename:=ThisWorkbook.Path & "\StoredNamedRangeNameObjects.xls"
    1040  Set WbNmeObjs = Workbooks("StoredNamedRangeNameObjects.xls")
    1050 '6b) Loop through all open workbooks and check named range object info
    1060 Dim Wbtemp As Workbook
    1070     For Each Wbtemp In Workbooks ' Going through each workbook in the Workbooks collection object of open workbooks
    1080      Call GeTchaNms(1080, Wbtemp)
    '1085        If Wbtemp.Name <> ThisWorkbook.Name Then Wbtemp.Close savechanges:=False ' Close all but this workbook - can't do this here - I might need them in the next use of GeTchaNms
    1090     Next Wbtemp
          'close workbooks
    1100     For Each Wbtemp In Workbooks ' Going through each workbook in the Workbooks collection object of open workbooks
    1110       If Wbtemp.Name <> ThisWorkbook.Name Then Wbtemp.Close savechanges:=False ' Close all but this workbook
    1120     Next Wbtemp
    
    End Sub

  6. #96
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    Support Called routines for Thread:
    http://www.excelfox.com/forum/showth...-a-named-range


    Code:
    Sub FukYaWkBkNames(ByVal WnkBuk As Workbook)
    Dim Nme As Name
        For Each Nme In WnkBuk.Names
         Nme.Delete
        Next Nme
    End Sub
    Sub GeTchaNms(ByVal CodLn As Long, ByVal WnkBuk As Workbook) ' To get info aboout all Name objects in a Workbook,m WnkBuk
    Dim Cnt As Long, Nme As Name, strOut As String
    ' Name objects in Workbook Names Colection object (Workbooks scope and Worksheets scope)
         For Each Nme In WnkBuk.Names '   For convenience it goes through the Workbook named  objects collection object  for a workbook, as this has "its own" named range objects, that is to say the Workbooks scoped named range objects, and also the  named range objects for all the worksheets. So I do not need to go through the named range objects collection object of every worksheet in that workbook separately for every worksheet.
          Let Cnt = Cnt + 1 ' A simple count number of each workbooks collection names objects in order it finds in looping them
          ' We look now for a "!" in the string name, ...  Excel adds a bit onto the name we give to a name Added to a Worksheet’s named objects collection ( Scoped to a Worksheet’s named objects collection = worksheet “scoping”     We scoped to the Names object of a particular Worksheet = We Added the named range Name object to the names objects collection object of that particular Worksheet( and also indirectly  the names objects collection object of the workbook in which that worksheet is) = We scoped that named range to that Workbook = That named range has Workbook Scope  ). That added bit is something like “Sheet1!” . In other words, if you had given Name:=”MyName” in a code line for a worksheets scope Named range object Addition, like, …_   Worksheets("Sheet2").Names.Add Name:="FoodHeader", RefersTo:=____    _.. Then excel seems to hold and use a name like “Sheet2!FoodHeader"
            If InStr(1, Nme.Name, "!", vbBinaryCompare) > 0 Then ' A name for a worksheet scope, has an extra bit added onto the name we gave it which includes a "!"
             Let strOut = strOut & Cnt & "  Name object Name is  """ & Nme.Name & """" & vbCrLf & "(you gave """ & Mid(Nme.Name, 1 + InStr(1, Nme.Name, "!", vbBinaryCompare)) & """)" & vbCrLf & "It has worksheet scope and" & vbCrLf & "it refers to range  """ & Nme.RefersTo & """" & vbCrLf & "and if in a spreadsheet formula you only want to use" & vbCrLf & """" & Mid(Nme.Name, 1 + InStr(1, Nme.Name, "!", vbBinaryCompare)) & """  without any preceding info about" & vbCrLf & "where that named range is," & vbCrLf & "then you must  be in spreadsheet with tab name  """ & Nme.Parent.Name & """" & vbCrLf & "If you want to be sure to access this named range from anywhere," & vbCrLf & "you should use   """ & "=" & "'" & WnkBuk.Path & "\" & "[" & WnkBuk.Name & "]" & Nme.Parent.Name & "'" & "!" & Mid(Nme.Name, 1 + InStr(1, Nme.Name, "!", vbBinaryCompare)) & """"
                If Nme.Parent.Name <> Application.Range(Nme.RefersTo).Parent.Name Then Let strOut = strOut & vbCrLf & "Note: The refered to range is in worksheet  """ & Application.Range(Nme.RefersTo).Parent.Name & """"
                If Nme.Parent.Parent.Name <> Application.Range(Nme.RefersTo).Parent.Parent.Name Then Let strOut = strOut & vbCrLf & "Note also: The refered to range is in File  """ & Application.Range(Nme.RefersTo).Parent.Parent.Name & """"
            Else ' Assume we have a workbook scoped name... we will see that a name for a workbook scope, remains just as we gave it
             Let strOut = strOut & Cnt & "  Name object Name is  """ & Nme.Name & """ (the same as you gave)" & vbCrLf & "It has workbook scope and" & vbCrLf & "it refers to range  """ & Nme.RefersTo & """" & vbCrLf & "and if in a spreadsheet formula you only want to use" & vbCrLf & """" & Nme.Name & """" & vbCrLf & "with no preceding info " & vbCrLf & "about where that named range is," & vbCrLf & "then you must be in any spreadsheet in workbook  """ & Nme.Parent.Name & """" & vbCrLf & "If you want to be sure to access this named range from anywhere," & vbCrLf & "you should use   """ & "=" & "'" & WnkBuk.Path & "\" & WnkBuk.Name & "'" & "!" & Nme.Name & """" & vbCrLf & "or alternatively use a similar string like this with any of the worksheets in it:" & vbCrLf & """" & "=" & "'" & WnkBuk.Path & "\" & "[" & WnkBuk.Name & "]" & WnkBuk.Worksheets.Item(1).Name & "'" & "!" & Nme.Name & """"
                If WnkBuk.Name <> Nme.Parent.Name Then Let strOut = strOut & vbCrLf & "Note the refered to range is in" & vbCrLf & """" & Application.Range(Nme.RefersTo).Parent.Parent.Name & """  worksheets  """ & Application.Range(Nme.RefersTo).Parent.Name & """  !!"
            End If
         Let strOut = strOut & vbCrLf & vbCrLf & vbCrLf ' To clearly seperate each name object
        Next Nme
        If strOut = "" Then
         MsgBox prompt:="The workbooks names object collection object is empty," & vbCrLf & "and so there are no named range objects in" & vbCrLf & "workbook   """ & WnkBuk.Name & """", Title:="At " & CodLn & " , for File  """ & WnkBuk.Name & """": Debug.Print "'_= ========" & vbCrLf & "You have no named range Name objects in workbook " & WnkBuk.Name & vbCrLf & vbCrLf
        Else
         MsgBox prompt:=strOut, Title:="At " & CodLn & " , """ & WnkBuk.Name & """ Names Collection has:-": Debug.Print "'_= ========" & vbCrLf & "You have " & Cnt & " named range Name objects in workbook " & WnkBuk.Name & vbCrLf & strOut
        End If
    End Sub

  7. #97
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10
    In support of this post:
    http://www.excelfox.com/forum/showth...0814#post10814


    _____ Workbook: MasturFile.xlsm ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    D
    1
    2
    3
    4
    Nutrition Energy
    5
    Food
    6
    Orange
    50
    7
    Apfel
    60
    8
    9
    10
    Suppliment
    11
    BCAA
    398
    12
    EAA
    400
    13
    14
    15
    Worksheet: Tabelle1
    Attached Files Attached Files

  8. #98
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    VBA named range scope not working through two closed workbooks

    I am trying to do 2 things: Use 2 named ranges.. One works. The other doesn’t.
    I have made a demo to help explain my problem
    I have 3 Files: I have a Main Excel workbook file, usually open, and two other files, usually closed
    _Main File is:- “Main.xls” https://app.box.com/s/u8yy4rcqg0eglvy362v13hyro8cgd9n7 – - This is usually open. It has all my codes in it
    _A DataFile is:- “ClsdData.xls.” https://app.box.com/s/65w1hnih1vvay70vtdzk3da50we3gxvh – This is usually closed. It has 2 data ranges and one named range name object in it
    ClsdDataDataRanges.JPG : https://imgur.com/vs0vX0G
    _____ Workbook: ClsdData.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    C
    1
    dataA1 dataB1
    2
    Worksheet: DataSht_1

    _A third file is:- “NameObjectFile.xls” https://app.box.com/s/wsxycb3t2y1hmv0wr12cqav0qlcytzjn – This is usually closed, ( preferably ). It only has a named range name object in it

    So the goal is to have a main file, “Main.xls” open whilst the files “ClsdData.xls.” and “NameObjectFile.xls” are closed, and from a code in the main file, “Main.xls” , put formulas of this sort of form in the first two cells of the main workbook.
    NamedRangeReferrenceFormulasPutInMainFile.JPG : https://imgur.com/1wDM3ug
    _____ Workbook: Main.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    1
    = ' C: \ FolderPath \ [ClsdData.xls] DataSht_1 ' ! NameForDataSht_1A1 = ' C: \ FolderPath \ [NameObjectFile.xls] NameObjectsSht_1 ' ! NameForDataSht_1B1
    Worksheet: Tabelle1
    Those formulas “go” to the name objects of the named ranges with string names:
    “ NameForDataSht_1A1” referring to the range of data file first cell ,
    and
    “NameForDataSht_1B1” referring to the range of data file second cell
    The result of those formulas should then be to have the actual seen values in those two cells as:
    MainFileDataIn.JPG : https://imgur.com/vQlhedZ
    _____ Workbook: Main.xls ( Using Excel 2007 32 bit )
    Row\Col
    A
    B
    1
    dataA1 dataB1
    Worksheet: Tabelle1
    ( I have determined that, contrary to much literature, you can actually access a named range from anywhere as long as you include the full path and full string range name: the so called “scope” only determines the default path that Excel uses if you only give the string range name )

    _._____________________
    Demo Code:
    (This code is in File: “Main.xls” )
    With all the files in the same Folder, this code can be used to make the two named range Name objects. ( I put one named range Name object in the first worksheet of the file: “ClsdData.xls” and the other named range Name object in the first worksheet of the file: “NameObjectFile.xls” ).
    The code also tries to access the first two cells values from the closed workbook using named ranges in these two code lines: The code lines put in those two long named range reference formulas
    Code:
     '_1 
    Workbooks("Main.xls").Worksheets.Item(1).Range("A1").Value = "='" & ThisWorkbook.Path & "\[ClsdData.xls]DataSht_1'!NameForDataSht_1A1"
    and
    Code:
    '_2 
    Workbooks("Main.xls").Worksheets.Item(1).Range("B1").Value = "='" & ThisWorkbook.Path & "\[NameObjectFile.xls]NameObjectsSht_1'!NameForDataSht_1B1"
    .
    Those are the two things I am trying to do.
    That last code line fails.
    That last code line does not fail if I have the workbook “NameObjectFile.xls” open
    Full Code:
    Code:
    Sub Make2NamedRangeObjectsAndTryToUseEm()
    ' scope named range to first worksheet's collection of Name objects object of Workbook "ClsdData.xls"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "ClsdData.xls"
     'Let Workbooks("ClsdData.xls").Worksheets.Item(1).Name = "DataSht_1"
     Workbooks("ClsdData.xls").Worksheets("DataSht_1").Names.Add Name:="NameForDataSht_1A1", RefersTo:=Workbooks("ClsdData.xls").Worksheets("DataSht_1").Range("A1")
     Workbooks("ClsdData.xls").Close savechanges:=True ' Save Added name object
    '_1 access first cell in closed data workbook from main file using named range name object with string name "NameForDataSht_1A1
     Let Workbooks("Main.xls").Worksheets.Item(1).Range("A1").Value = "='" & ThisWorkbook.Path & "\[ClsdData.xls]DataSht_1'!NameForDataSht_1A1"
     Workbooks("Main.xls").Save
    ' scope named range to first worksheet's collection of Name objects object of Workbook "NameObjectFile.xls "
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "NameObjectFile.xls"
     'Let Workbooks("NameObjectFile.xls").Worksheets.Item(1).Name = "NameObjectsSht_1"
     Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "ClsdData.xls" ' Needed for RefersTo below
     Workbooks("NameObjectFile.xls").Worksheets("NameObjectsSht_1").Names.Add Name:="NameForDataSht_1B1", RefersTo:=Workbooks("ClsdData.xls").Worksheets("DataSht_1").Range("B1")
     Workbooks("ClsdData.xls").Close savechanges:=False ' No changes made - was only needed for RefersTo above
     Workbooks("NameObjectFile.xls").Close savechanges:=True ' Save Added name object
    '_2 access second cell in closed dataworkbook from main file using named range name object with string  NameForDataSht_1B1
     Let Workbooks("Main.xls").Worksheets.Item(1).Range("B1").Value = "='" & ThisWorkbook.Path & "\[NameObjectFile.xls]NameObjectsSht_1'!NameForDataSht_1B1"
    
    End Sub
    _.__________
    Let me put again into words what I am doing. I am doing two things:

    '_1 This works: I have a closed data workbook, ("ClsdData.xls" ). That has a named range, ( string name is “NameForDataSht_1A1” ) . That name, “NameForDataSht_1A1” , is for the first cell in that closed data workbook, ("ClsdData.xls" ). That named range is scoped to the first worksheet in that closed data file, (closed data workbook, ("ClsdData.xls" ) . In other words, the named range object with string name “NameForDataSht_1A1” is in the first worksheets name objects collection of the closed data workbook ( "ClsdData.xls" ). This named range object with string name “NameForDataSht_1A1” refers to the first cell, A1, in the closed data workbook, ("ClsdData.xls" ).

    '_2 This does not work , ( unless file "NameObjectFile.xls" is open ). I am using a file, ( "NameObjectFile.xls" ), only for holding name range objects. It has one named range name object in it which has the string name "NameForDataSht_1B1". This is the name range object for the second cell in the closed data workbook, ("ClsdData.xls" ). In other words, the named range object with string name “NameForDataSht_1B1” is in the first worksheets name objects collection of the workbook “NameObjectFile.xls”. This named range object with string name “NameForDataSht_1B1” refers to the second cell, B1, in the closed data workbook, ("ClsdData.xls" ).

    I don’t understand yet why '_2 does not work. I am not totally sure why '_1 does work either.
    I guess I don’t really understand exactly what I am doing. I don’t really understand what is really going on in the two cases.

    I am thinking that I should be able somehow to get the string reference information that I require , that is to say, for the right hand side of the last equation I have this:
    "='" & ThisWorkbook.Path & "\[NameObjectFile.xls]NameObjectsSht_1'!NameForDataSht_1B1"
    But somehow I am thinking that I should be able to get the referred to string reference of
    "='" & ThisWorkbook.Path & "\ [ClsdData.xls]DataSht_1'!$A$1"

  9. #99
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    NameObjectFile.xls as Zip

    I did this..
    Took file “NameObjectFile.xls”,
    first save as .xlsx,
    then save as .zip ( “NameObjectFile - Kopie.zip” : https://app.box.com/s/ih9k6o7s5f3vkb21jyyso0mcqoh82isb )
    and then double click on it and get this: NameObjectFile_xls_xlsx_zip.JPG : https://imgur.com/iAVFSOh




    I get stuff like this:
    _____ Workbook: Main.xls ( Using Excel 2007 32 bit )
    NameObjectsFileAsZip NameObjectsFileAsZip
    [Content_Types].xml
    NameObjectsFileAsZip\docProps docProps
    app.xml
    core.xml
    thumbnail.wmf
    NameObjectsFileAsZip\xl xl
    styles.xml
    workbook.xml
    NameObjectsFileAsZip\xl\externalLinks externalLinks
    externalLink1.xml
    NameObjectsFileAsZip\xl\externalLinks\_rels _rels
    externalLink1.xml.rels
    NameObjectsFileAsZip\xl\theme theme
    theme1.xml
    NameObjectsFileAsZip\xl\worksheets worksheets
    sheet1.xml
    NameObjectsFileAsZip\xl\_rels _rels
    workbook.xml.rels
    NameObjectsFileAsZip\_rels _rels
    .rels
    Worksheet: NameObjectsFileAsZip

    NameObjectsFileAsZip_NameObjectsFileAsZip
    _____________________[Content_Types].XML Content Types--xml.jpg . https://imgur.com/n9FQUxR
    ________________
    NameObjectsFileAsZip\docProps_______docProps docProps.JPG : https://imgur.com/SRBBdyg
    ____________________________________app.XML app xml.JPG : https://imgur.com/qeeWrpm
    ____________________________________core.XML core xml.JPG : https://imgur.com/jZ3iSo7
    ____________________________________thumbnail.wmf
    ________________
    NameObjectsFileAsZip\xl_____________xl xl.JPG : https://imgur.com/408pO7A
    ____________________________________Styles.XML styles xml.JPG : https://imgur.com/71fDgcw
    ____________________________________Workbook.XML workbook xml.JPG : https://imgur.com/AJ3et9N
    ________________
    NameObjectsFileAsZip\xl\externalLinks___________externalLinks externalLinks.JPG : https://imgur.com/SPj3lZY
    ________________________________________________ex ternalLink1.XML externalLink1 xml rels.JPG : https://imgur.com/qHnFz7u
    ________________
    NameObjectsFileAsZip\xl\externalLinks\_rels______________rels _ rels.JPG : https://imgur.com/GwEBoFG
    __________________________________________________ _______externalLink1.XML.rels externalLink1 xml rels.JPG : https://imgur.com/qHnFz7u
    ________________
    NameObjectsFileAsZip\xl\theme___________________theme theme.JPG : https://imgur.com/KyceI30

    ________________________________________________th eme1.XML theme1 xml.JPG : https://imgur.com/hGgsgOQ
    ________________
    NameObjectsFileAsZip\xl\worksheets______________worksheets worksheets.JPG : https://imgur.com/D8hqFpr
    ________________________________________________sh eet1.XML Sheet1 xml.JPG : https://imgur.com/ycxiL62
    ________________
    NameObjectsFileAsZip\xl\_rels____________________rels _ rels.JPG https://imgur.com/u84DcoX

    ________________________________________________Wo rkbook.XML.rels workbook xml rels.JPG : https://imgur.com/L8fNakM
    ________________
    NameObjectsFileAsZip\_rels___________rels _rels.JPG https://imgur.com/Tahoick
    ____________________________________.rels rels.jpg . https://imgur.com/pWaSeIo

  10. #100
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    9,521
    Rep Power
    10

    ClsData.xls as Zip File

    I took this, “ClsdData.xls” , saved it as “ClsdData.xlsx” ,
    then changed it to “ClsdData.zip” ,
    closed it,
    then double clicked on it and get this:
    ClsdDataZip.JPG : https://imgur.com/oUtHu34
    I copied all that to one folder,
    and put that Folder in another folder:
    copied all that to one folder, and put that Folder in another folder.JPG : https://imgur.com/an58FA7
    I ran the code Sub DoStuffInFoldersInFolderRecursion() which is in the uploaded version of “Main.xls” , and that gives a Folder and File tree something like this if you select one of the above folders when it asks you to select a Folder:
    _____ Workbook: Main.xls ( Using Excel 2007 32 bit )
    FolderForClsdDataZipContents FolderForClsdDataZipContents
    [Content_Types].xml
    FolderForClsdDataZipContents\docProps docProps
    app.xml
    core.xml
    thumbnail.wmf
    FolderForClsdDataZipContents\xl xl
    sharedStrings.xml
    styles.xml
    workbook.xml
    FolderForClsdDataZipContents\xl\theme theme
    theme1.xml
    FolderForClsdDataZipContents\xl\worksheets worksheets
    sheet1.xml
    FolderForClsdDataZipContents\xl\_rels _rels
    workbook.xml.rels
    FolderForClsdDataZipContents\_rels _rels
    .rels
    Worksheet: ClsdDataZipTree



    'FolderForClsdDataZipContents_FolderForClsdDataZip Contents
    '__________________________[Content_Types].XML
    '
    'FolderForClsdDataZipContents\docProps_______docPr ops docProps.JPG : https://imgur.com/6i1gIK4
    '____________________________________________app.X ML app XML.JPG : https://imgur.com/XxiZCL9
    '____________________________________________core. XML core XML.JPG : https://imgur.com/BwQxqi6
    '____________________________________________thumb nail.wmf
    '
    'FolderForClsdDataZipContents\xl_____________xl xl.JPG : https://imgur.com/YxJFYV4
    '____________________________________________share dStrings.XML sharedStrings XML.JPG : https://imgur.com/7dSdvM6
    '____________________________________________Style s.XML Styles XML.JPG : https://imgur.com/whytQOj
    '____________________________________________Workb ook.XML Workbook XML.JPG: https://imgur.com/P3G2qNC
    '
    'FolderForClsdDataZipContents\xl\theme____________ theme theme.JPG : https://imgur.com/Vj2RSyM
    '_________________________________________________ theme1.XML theme1 XML.JPG : https://imgur.com/zimRsPL
    '
    'FolderForClsdDataZipContents\xl\worksheets_______ worksheets worksheets.JPG : https://imgur.com/O8KBgSB
    '_________________________________________________ sheet1.XML sheet1 XML.JPG : https://imgur.com/LWVPyXn
    '
    'FolderForClsdDataZipContents\xl\_rels____________ _rels xl_rels.JPG : https://imgur.com/fwYmQwR
    '_________________________________________________ Workbook.XML.rels Workbook XML rels.JPG : https://imgur.com/NOxE816
    '
    'FolderForClsdDataZipContents\_rels___________rels _rels.JPG : https://imgur.com/RTVajJI
    '____________________________________________.rels Dot rels.JPG : https://imgur.com/NOxE816

Similar Threads

  1. Notes tests, Scrapping, YouTube
    By DocAElstein in forum Test Area
    Replies: 221
    Last Post: 10-02-2022, 06:21 PM
  2. Replies: 1
    Last Post: 02-06-2022, 03:14 PM
  3. Gif Image Video stuff testies
    By DocAElstein in forum Test Area
    Replies: 13
    Last Post: 09-06-2021, 01:07 PM
  4. Test excelfox Corruptions January 2021 *
    By DocAElstein in forum Test Area
    Replies: 13
    Last Post: 01-25-2021, 08:07 PM
  5. Replies: 8
    Last Post: 08-17-2013, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •