Skip to main content

Conas airíonna uile chomhad Excel a liostáil i mbileog?

San Airteagal seo, tugaim isteach cód VBA chun airíonna uile an leabhair oibre ghníomhaigh a liostáil i mbileog.

1. Brúigh Alt + F11 eochracha chun an fhuinneog Microsoft Visual Basic for Applications a chumasú.

2. cliceáil Ionsáigh > Modúil, agus greamaigh thíos an cód leis an modúl bán.

VBA: Liostaigh na hairíonna go léir

Sub WBProperties()
'UpdatebyKutools20191031
    Dim xWB As Workbook
    Dim xF As Long
    Dim xStr As String
    Dim xWSh As Worksheet
    On Error Resume Next
    Application.DisplayAlerts = False
    xStr = "Workbook Properties"
    Set xWB = Application.ActiveWorkbook
    Set xWSh = xWB.Worksheets.Item(xStr)
    If Not xWSh Is Nothing Then
        xWSh.Delete
    End If
    Set xWSh = xWB.Worksheets.Add
    xWSh.Name = xStr
    xWSh.Range("A1").Value = "Property"
    xWSh.Range("B1").Value = "Value"
    With xWB
        For xF = 1 To .BuiltinDocumentProperties.Count
            xWSh.Range("A65536").End(xlUp).Offset(1, 0).Value = _
            .BuiltinDocumentProperties.Item(xF).Name
            xWSh.Range("A65536").End(xlUp).Offset(0, 1).Value = _
            .BuiltinDocumentProperties.Item(xF).Value
        Next xF
    End With
    Application.DisplayAlerts = True
End Sub

liosta doc go léir cuir isteach 1

3. Brúigh F5 eochair chun an cód a rith, cruthaíodh bileog nua darb ainm Airíonna Leabhar Oibre os comhair an bhileog ghníomhaigh, a liostaíonn airíonna uile an leabhair oibre ghníomhaigh.
liosta doc go léir cuir isteach 1


Oibríochtaí Eile (Ailt)

Díchumasaigh breiseáin ag am tosaithe Excel
B’fhéidir go bhfuil roinnt breiseán suiteáilte agat i do Microsoft Excel, ach anois ní mór duit breiseán sonraithe a dhíchumasú ag am tosaithe Excel. Conas an fhadhb seo a réiteach? Is féidir le modh san alt seo cabhrú leat.

Easpórtáil agus sábháil gach bileog oibre mar leabhar oibre nua ar leithligh in Excel
Ligean le rá gur mhaith leat bileog oibre amháin nó níos mó a easpórtáil agus a shábháil mar leabhar oibre nua, conas a dhéileálfaidh tú leis? De ghnáth is féidir leat gach bileog oibre a chóipeáil agus a ghreamú de leabhar oibre nua. Ach anseo tugann muid roinnt cleasanna úsáideacha duit chun déileáil leis:

Cód VBA chun gach breiseán a liostáil in Excel
In Excel, féadfaidh tú roinnt breiseán a chur leis nó a chur isteach chun déileáil níos fearr le sonraí. Mar is eol dúinn, is féidir linn dul go dtí an fhuinneog Roghanna chun gach breiseán a fheiceáil, ach an bhfuil aon bhealach ann gach breiseán a liostáil i mbileog?


  • Barra Foirmle Super (cuir línte iolracha téacs agus foirmle in eagar go héasca); Leagan Amach Léitheoireachta (líon mór cealla a léamh agus a chur in eagar go héasca); Greamaigh go dtí an Raon Scagtha...
  • Cumaisc Cealla / Sraitheanna / Colúin agus Sonraí a Choinneáil; Ábhar Cealla Scoilt; Comhcheangail Sraitheanna Dúblacha agus Suim / Meán... Cill Dúblach a Chosc; Déan comparáid idir Ranganna...
  • Roghnaigh Dúblach nó Uathúil Sraitheanna; Roghnaigh Blank Rows (tá na cealla uile folamh); Aimsigh Super agus Fuzzy Aimsigh i go leor Leabhar Oibre; Roghnaigh go randamach ...
  • Cóip Díreach Cealla Il gan tagairt fhoirmle a athrú; Tagairtí Cruthaigh Auto chuig Bileoga Il; Cuir Urchair isteach, Boscaí Seiceála agus go leor eile ...
  • Foirmlí is Fearr agus Cuir isteach go tapa, Ranganna, Cairteacha agus Pictiúir; Cealla a Chriptiú le pasfhocal; Cruthaigh Liosta Ríomhphoist agus seol ríomhphoist ...
  • Sliocht Téacs, Cuir Téacs leis, Bain de réir Poist, Bain Spás; Subtotals Paging a chruthú agus a phriontáil; Tiontaigh Idir Ábhar Cealla agus Tráchtanna...
  • Scagaire Super (scéimeanna scagaire a shábháil agus a chur i bhfeidhm ar bhileoga eile); Ard-Sórtáil de réir míosa / seachtaine / lae, minicíocht agus níos mó; Scagaire Speisialta le cló trom, iodálach ...
  • Comhcheangail Leabhair Oibre agus Bileoga Oibre; Cumaisc Táblaí bunaithe ar eochaircholúin; Roinn Sonraí i Ilbhileoga; Baisc Tiontaigh xls, xlsx agus PDF...
  • Grúpáil Tábla Pivot de réir uimhir na seachtaine, lá na seachtaine agus níos mó ... Taispeáin Cealla Díghlasáilte, Faoi Ghlas de réir dathanna éagsúla; Aibhsigh Cealla a bhfuil Foirmle / Ainm orthu...
cluaisín kte 201905
  • Cumasaigh eagarthóireacht agus léamh tabbed i Word, Excel, PowerPoint, Foilsitheoir, Rochtain, Visio agus Tionscadal.
  • Oscail agus cruthaigh cáipéisí iolracha i gcluaisíní nua den fhuinneog chéanna, seachas i bhfuinneoga nua.
  • Méadaíonn do tháirgiúlacht 50%, agus laghdaíonn sé na céadta cad a tharlaíonn nuair luch duit gach lá!
bun officetab
Comments (1)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello,

First off, I do not know VBA, but have determined after hours of searching, it is the only solution to my problem.

Background:
I have a workbook with a large number of Power Query-created "Merge"-type Queries and Queries that pull data from flat files; some, but not all are added to the Data Model/Power Pivot.

The composition of queries may change over time.

Within a subset of the queries, I have disabled refreshing with "Refresh All" to reduce the already lengthy time it takes to refresh all queries.

There are a large number of worksheets that contain Pivots off the Data Model, whereas the others contain a subset of tables that are populated from the queries via "Load To"

I am using O365 Excel

The example code below is based on hours of research. I don't know if it's of value in achieving my objectives below, but I'm including it in the event it sparks a solution.

Objectives:
I would like an "index" worksheet created containing a dynamic table (or just listed out in cells that I can convert to a table manually) that keeps an up-to-date list of workbook "Query-" queries and their respective properties below.

The dynamic (e.g., reflect added/changed/deleted queries) table should contain the following columns with the following query/connection properties as fields:
-----------------------------------------------------
"Name", "Description", "RefreshWithRefreshAll", "InModel", "Type"

The following example is what I was able to cobble together from the interwebs which got me some of the way there, but it only allows me to see it in the VBA Immediate window, and I don't know how to get it into a table on the worksheet:

Sub ListConnections()

Dim cn As WorkbookConnection

Debug.Print "Name", "|", "Description", "|", "|", "RefreshWithRefreshAll", "|", "InModel", "|", "Type"


For Each cn In ThisWorkbook.Connections
Debug.Print cn.Name, "|", cn.Description, "|", cn.RefreshWithRefreshAll, "|", cn.InModel, "|", cn.Type

Next
End Sub-----------------------------------------------------

Currently, I can only get it to output in the Immediate Window:
-----------------------------------------------------
Name|Description||RefreshWithRefreshAll|InModel|Type
ModelConnection_ExternalData_1|DataModel|True|True|7
ModelConnection_ExternalData_11|DataModel|True|True|7
Query-AllADMembers(CX)|Connectiontothe'AllADMembers(CX)'queryintheworkbook.|True|True|1
Query-AllAzureADUsers-Disabled|Connectiontothe'AllAzureADUsers-Disabled'queryintheworkbook.|True|False|1
Query-AllAzureADUsers-Enabled|Connectiontothe'AllAzureADUsers-Enabled'queryintheworkbook.|True|False|1
Query-AllAzureADUsersOnly|Connectiontothe'AllAzureADUsersOnly'queryintheworkbook.|True|False|1
...

Query-UsersinDA,NotinApp-BulkDEL*|Connectiontothe'UsersinDA,NotinApp-BulkDEL*'queryintheworkbook.|False|True|1
ThisWorkbookDataModel|DataModel|True|True|7
-----------------------------------------------------
Note 1: I used the convention of adding an asterisk to the query name to visually see which queries I disabled refreshing with Refresh All.
Note 2: Query names with (CNX) refer to the base queries to the flat files upon which the other merge queries are based.
Note 3: The "Last Refresh" field in the table would be the Date/Time of the Last Refresh of the query. I was hoping it could be obtained as a property of the query, since this timestamp is shown when hovering over the query in the query pane, e.g.

<br style="letter-spacing: 0.2px;">
Based on my searches, it does not appear that this is obtainable for some reason, but if not, I found other references to adding it as a calculated value using timestamps of macro executed refreshes.

Example: I found many references to adding a button to have a macro refresh one or refresh all queries. My thought is that one could create code to dynamically enumerate the names from the code above Query-[Query Name], then have the code execute a refresh of each (CNX) query above first, then execute the rest individually to capture the execution and/or finish timestamp. Since there is a natural sequence that Excel uses when doing a refresh all, executing queries manually may trigger the natural sequence multiple times making the overall refresh times unbearable. Looking for the most efficient solution here.

Here is some code that I thought would be useful to tackle this, but again, it only shows output in the Immediate Window when executed.
-----------------------------------------------------
Dim TStart As Date
Dim TEnd As Date
Dim cn As WorkbookConnection

For Each cn In ThisWorkbook.Connections

If Left(cn, 13) = "Power Query -" Then
Debug.Print cn
TStart = Now
cn.Refresh
TEnd = Now
Debug.Print CStr(DateDiff("s", TStart, TEnd)) + " Seconds"
Debug.Print ""

End If
Next cn
End Sub
-----------------------------------------------------
Thanks in advance!

M
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations