• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Is there any similar M code for Excel.CurrentWorkbook( ) for bring in external xlsx to a blank worksheet|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Is there any similar M code for Excel.CurrentWorkbook( ) for bring in external xlsx to a blank worksheet|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryIs there any similar M code for Exc…
sp_PrintTopic sp_TopicIcon
Is there any similar M code for Excel.CurrentWorkbook( ) for bring in external xlsx to a blank worksheet
Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
1
November 22, 2019 - 12:41 am
sp_Permalink sp_Print

Hi,

I was amazed by the M code Excel.CurrentWorkbook( ) that allow us to append several worksheets easily,  without using Append query in PQ editor

Is there any equivalent M code for bringing in worksheets from various sources ( D drive,  server drive) into Power Query, without bringing in the physical tables ( or minimally) into one single query just like Excel.CurrentWorkbook( )

for e.g.

I open a new workbook,  open a blank query at formula bar key in equivalent M code to bring in PC_1 ad PC_2 tables from the attach

Thank you !

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
November 22, 2019 - 4:24 am
sp_Permalink sp_Print

Hi Chris,

Not sure what you want.

D Drive I guess is a local drive?

You can use File.Contents(FilePath) , this will return file data in binary format, then you can add a new column with the formula =Excel.Workbook([Content]) to extract data from the file.

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
3
November 22, 2019 - 3:09 pm
sp_Permalink sp_Print

Hi Catalin,

I try to explain,, 

in my attached example, because the source file is in the excel itself,  I can use =Excel.CurrentWorkbook( )   in the blank query and that it

what if I open up a blank excel workbook,   open a blank query,  you mean I can use =File.Contents( d:\temp\file.xlsx) to import in ?

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
4
November 22, 2019 - 3:24 pm
sp_Permalink sp_Print

Hi Catalin,  basically I want to just issue a M code that will consolidate all the worksheets like what Excel.CurrentWorkbook( )  did,   i.e.  instead of import physically to PQ and then use Append query to combine them

Is this possible ?

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1810
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
5
November 22, 2019 - 8:07 pm
sp_Permalink sp_Print sp_EditHistory

Hi Chris,

Attached is an example, you can use that, or start with a blank query with this formula:

= Excel.Workbook(File.Contents("C:\Users\Catalin\Desktop\New folder\SourceTable.xlsx"), null, true)

This will give you the list of sheets in that workbook, you can select the ones you want and expand the data table.

As mentioned, I only used File.Contents()  and Excel.Workbook() to extract data from the file.

Nothing is stopping you from trying, I think trying things is the best way to go, even if it fails sometimes.

Avatar
Chris Yap
Member
Members
Level 0
Forum Posts: 162
Member Since:
August 21, 2019
sp_UserOfflineSmall Offline
6
November 22, 2019 - 10:47 pm
sp_Permalink sp_Print

Hi Catalin,  perfect !  this is exactly what I am looking for,  however some users still like to import all the tabs into PQ and append it

so I thought by just writing this short code ( thanks to you !!)

= Excel.Workbook(File.Contents("C:\Users\JO_HOME\Downloads\temp\ExcelCurrentWorkbook.xlsx"), null, true)

it is clean,  light and display what I want,  the master combined dataset

 

Chris Yap

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Nada Perovic, Denise Lloyd
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 871
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Raj Mattoo
Mark Luke
terimeri dooriyan
Jack Aston
AndyC
Denise Lloyd
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Forum Stats:
Groups: 3
Forums: 24
Topics: 6219
Posts: 27276

 

Member Stats:
Guest Posters: 49
Members: 31903
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.