@manhng

Welcome to my blog!

Excel Interop

January 27, 2022 10:56

Excel Interop (edit)

How to access Office interop objects - C# Programming Guide | Microsoft Docs

How to Create Word Document Using C# (c-sharpcorner.com)

using Excel = Microsoft.Office.Interop.Excel;
using Word = Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
using Microsoft.Vbe.Interop;

  • %ProgramFiles%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\

  • %ProgramFiles(x86)%\Microsoft Visual Studio\Shared\Visual Studio Tools for Office\PIA\

How to create Excel file in C# (net-informations.com)

  • using System.Runtime.InteropServices;
  • using Microsoft.Office.Interop.Excel;
  • using Microsoft.Office.Interop.Word;
  • using Microsoft.Vbe.Interop; //C# How Do I Insert Macro Into Excel VBA?
            try
            {
                //create new instance
                excelApp = new Excel.Application();

                //suppress displaying alerts (such as prompting to overwrite existing file)
                excelApp.DisplayAlerts = false;

                //set Excel visability
                excelApp.Visible = true;

...
} catch (Exception ex) { string errMsg = "Error (WriteToExcel) - " + ex.Message; System.Diagnostics.Debug.WriteLine(errMsg); if (ex.Message.StartsWith("Cannot access read-only document")) { System.Windows.Forms.MessageBox.Show(ex.Message + "Please close the workbook, before trying again.", "Error - Unable To Write To Workbook", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } finally { if (workbook != null) { //close workbook workbook.Close(); //release all resources System.Runtime.InteropServices.Marshal.FinalReleaseComObject(workbook); } if (excelApp != null) { //close Excel excelApp.Quit(); //release all resources System.Runtime.InteropServices.Marshal.FinalReleaseComObject(excelApp); } }

C# COM Interop Excel: How to write to cells from C# using Interop Excel? - Stack Overflow (HAY HAY HAY)

Creating Excel File using Interop Services (c-sharpcorner.com) (HAY HAY HAY)

How to Read an Excel file in Windows Forms Application using C# and Vb.Net (encodedna.com) (HAY HAY HAY)

How to access Office Interop Objects in C# | CodeGuru.com (Word + Excel)

How to automate Microsoft Excel from Microsoft Visual C#.NET - Office | Microsoft Docs

  1. Right click into Project > References > Add Reference..
  2. On the COM tab, locate Microsoft Excel Object Library

How to access Office interop objects - C# Programming Guide | Microsoft Docs

using Microsoft.Office.Interop.Excel;

string path = "C:\\Projects\\ExcelInterop\\Test.xlsx ";

Application excelApp = new Application();
Workbook excelWorkbook = excelApp.Workbooks.Open(path);
Worksheet excelWorksheet = excelWorkbook.ActiveSheet;

You have two ways to get the value

using xl = Microsoft.Office.Interop.Excel;

// 1. Using Cells with numbered reference
string cellValue = (excelWorksheet.Cells[10, 2] as xl.Range).Text.ToString();

// 2. Using Range with address reference
string cellValue = excelWorksheet.Range["J2"].Text.ToString();

Excel's VBA

Excel VBA Object Model And Object References: The Essential Guide (powerspreadsheets.com)

If you want to really master Excel macros and Visual Basic for Applications, you must have a good understanding of the following 3 topics:

  • Objects.
  • How to manipulate VBA objects.
  • Excel's VBA object model.

Chapters

excel-vba eBook (riptutorial.com)

What is Microsoft.Vbe.Interop.dll?

Office primary interop assemblies - Visual Studio (Windows) | Microsoft Docs

Microsoft.Vbe.Interop.dll is part of Microsoft Office 2013 and developed by Microsoft Corporation according to the Microsoft.Vbe.Interop.dll version information.

Microsoft.Vbe.Interop.dll's description is "Microsoft.Vbe.Interop"

Microsoft.Vbe.Interop.dll is digitally signed by Microsoft Corporation.

Microsoft.Vbe.Interop.dll is usually located in the 'c:\Program Files\WinZip\' folder.

None of the anti-virus scanners at VirusTotal reports anything malicious about Microsoft.Vbe.Interop.dll.

If you have additional information about the file, please share it with the FreeFixer users by posting a comment at the bottom of this page.

Vendor and version information

The following is the available information on Microsoft.Vbe.Interop.dll:

Product name Microsoft Office 2013
Company name Microsoft Corporation
File description Microsoft.Vbe.Interop
Internal name Visual Basic Extensions Primary Interop Assembly
Original filename Visual Basic Extensions Primary Interop Assembly
Product version 15.0.4420.1017
File version 15.0.4420.1017

Here's a screenshot of the file properties when displayed by Windows Explorer:

Product name Microsoft Office 2013
Company name Microsoft Corporation
File description Microsoft.Vbe.Interop
Internal name Visual Basic Extensions Primary Inte..
Original filename Visual Basic Extensions Primary Inte..
Product version 15.0.4420.1017
File version 15.0.4420.1017

Digital signatures

Microsoft.Vbe.Interop.dll has a valid digital signature.

Signer name Microsoft Corporation
Certificate issuer name Microsoft Code Signing PCA
Certificate serial number 3300000088590e3c511fe26a67000100000088

VirusTotal report

None of the 48 anti-virus programs at VirusTotal detected the Microsoft.Vbe.Interop.dll file.

VBA + VB.Net and Java

January 25, 2022 17:16

VBA + VB.Net and Java (edit)

  • VB6
  • VB6  for Access 2016
  • VBA
  • VBA for Excel
  • VB.NET
  • Java

App:

  • Word
    • Table
    • Image
  • Excel
    • Excel Chart
    • Excel Range
    • Excel Image
  • PowerPoint
  • PDF
  • Microsoft Print to PDF

Concept:

  • Coding Standards and Code Reviews
  • Coding Techniques
  • Best Practices
  • Conclusion
  • Suggested Reading​

RVBA Naming Conventions - Xoc Software (RVBA Conventions, Maya Calendar, et.al.)

Object Naming Conventions | Microsoft Docs (VB6)

Constant and Variable Naming Conventions | Microsoft Docs (VB6)

Structured Coding Conventions | Microsoft Docs (VB6)

Visual Basic for Applications - Excel VBA - The full course | Udemy

  • create your own macro in Excel
  • program in VBA
  • understand Visual Basic for Applications
  • create automated reports in Excel
  • develop your applications and tools in Excel

Visual Basic for Microsoft Access Tutorial | Udemy

Visual Basic 6.0 Tutorial: Getting Started With Visual Basic Programming - Udemy Blog

Visual Basic Timer: How to Use It to Schedule Your Tasks - Udemy Blog

C# and Access 2016

C# Database Driven WinForm Apps (step by step projects) | Udemy

  • Students will understand the basics of database programming using C# and MS Access database.
  • Students will become familiar with database programming concepts.
  • Students will be able to create small database-driven desktop apps.
  • Students will understand basics of database concepts.
  • Students will be able to create and modify Windows Forms and bind form objects with database objects.
  • Students will be ready to tackle more complex projects.
  • Visual Studio
  • Basic familiarity with Windows Forms
  • Basic C# Skills (loops, conditional statements, very basics of OOP etc.)
  • Basic knowledge of Database terminology

VB and Access

Microsoft Access, SQL: Visual Basic, Database Administration | Udemy

VB.NET

VB.NET Masterclass: Learn Visual Basic and VBScript | Udemy

Learning Visual Basic .NET Tutorials: VB.NET Programming | Udemy

Coding Conventions - Visual Basic | Microsoft Docs

Visual Basic .NET Tutorial for Beginners Make App That Sells | Udemy

Visual Basic .NET Programming for Complete Beginners | Udemy

  • Produce Windows Console Applications
  • Learn the fundamentals of Visual Basic .NET
  • How to understand and write simple Visual Basic .NET programs
  • Design and build Windows Forms Application
  • By learning Visual Basic .NET Basics, you will be able to jump quickly into the intermediate level of this programming language
  • Create a database in Microsoft Access 2016
  • Connect to Access database by using commands in a central module
  • Do Simple Data Binding and Complex Data Binding
  • Manage data in the database by doing CRUD Operations
  • Write SQL statements for retrieving and searching from a single point
  • Create a Product Management System (Complete CRUD Application)
  • Create Multiple Document Interface (MDI) Application

Some pet projects:

  • Create and write Excel files in C# and VB.NET
  • Create an Excel (XLSX) or PDF file in ASP.NET
  • Create Excel Chart in C# and VB.NET
  • Open and read Excel files in C# and VB.NET
  • Read and write CSV (or TSV) in C# and VB.NET
  • Convert Excel files to PDF in C# and VB.NET
  • Convert Excel files to image formats in C# and VB.NET
  • Convert Excel files to HTML in C# and VB.NET
  • Print Excel files in C# and VB.NET
  • Export Excel files from ASP.NET GridView
  • Export a DataTable or DataSet to an Excel file in C# and VB.NET
  • Export Excel sheet into DataTable in C# and VB.NET
  • Import and Export Excel to DataGridView in C# and VB.NET
  • Referencing Excel cell and range in C# and VB.NET
  • Excel Formula Calculation in C# and VB.NET

VBA & Outlook

June 19, 2020 10:40

VBA & Outlook (edit)

Office developer documentation

https://developer.microsoft.com/en-us/office/docs

Outlook add-ins documentation

https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/

Program VSTO Add-ins

https://docs.microsoft.com/en-us/visualstudio/vsto/programming-vsto-add-ins?view=vs-2017

private void ThisAddIn_Startup(object sender, System.EventArgs e) { ... }

VSTO Add-ins

https://docs.microsoft.com/en-us/visualstudio/vsto/walkthrough-creating-your-first-vsto-add-in-for-outlook?view=vs-2017

private void ThisAddIn_Startup(object sender, System.EventArgs e) { ... }

VSTO Add-ins for Office

https://docs.microsoft.com/en-us/visualstudio/vsto/create-vsto-add-ins-for-office-by-using-visual-studio?view=vs-2017

Outlook Object Model

https://docs.microsoft.com/en-us/visualstudio/vsto/outlook-object-model-overview?view=vs-2017

VBA

https://www.thoughtco.com/timer-in-office-vba-macros-3424056

Outlook

Launching Outlook at startup (in a smarter way)

https://www.msoutlook.info/question/442

10 tips for speeding up Outlook

https://www.techrepublic.com/blog/10-things/10-tips-for-speeding-up-outlook/

Top 10 annoyances and how to fix them

Annoyances: phiền toái

Annoyance No. 1: Outlook is too darn slow. How can I speed it up?

https://www.computerworld.com/article/2530153/hate-microsoft-outlook-top-10-annoyances-and-how-to-fix-them.html

Annoyance No. 2: Outlook's attachments make it massively bloated.

https://www.computerworld.com/article/2530153/hate-microsoft-outlook-top-10-annoyances-and-how-to-fix-them.html?page=2

Annoyance No. 3: Why can't I find where my $#%^(@"* Outlook data is stored?

Annoyance No. 8: Why can't I synchronize Outlook on multiple PCs?

https://www.computerworld.com/article/2530153/hate-microsoft-outlook-top-10-annoyances-and-how-to-fix-them.html?page=6

Annoyance No. 10: Why won't Outlook work seamlessly with Gmail?

https://www.computerworld.com/article/2530153/hate-microsoft-outlook-top-10-annoyances-and-how-to-fix-them.html?page=7

Tips & Tricks for Outlook

https://www.outlook-apps.com/outlook-tips/

Tutorials 

https://www.outlook-apps.com/tutorials/

https://www.howto-outlook.com/

Launching Outlook at startup (in a smarter way)

https://www.msoutlook.info/question/442

Outlook 2010

https://www.wikihow.com/Configure-Outlook-2010
https://www.wikihow.com/Access-Gmail-in-Outlook-2010
https://www.howtogeek.com/353584/how-to-use-gmail-with-microsoft-office/

Folder & Path

https://www.ryadel.com/en/microsoft-office-default-installation-folders-versions/

Outlook 2010:
C:\Program Files\Microsoft Office\Office14\
C:\Program Files (x86)\Microsoft Office\Office14\

Outlook 2013:
C:\Program Files\Microsoft Office\Office15\
C:\Program Files (x86)\Microsoft Office\Office15\

C:\Users\nvmanh\AppData\Roaming\Microsoft\Outlook\

C:\Users\nvmanh\Documents\Outlook Files\

Outlook Free Lancer

https://www.freelancer.co.za/projects/c-sharp-programming/complete-outlook-addin/

Code Samples

https://docs.microsoft.com/en-us/samples/browse/?redirectedfrom=MSDN-samples 

Office Add-ins Patterns and Practices (PnP)

Office 365 solution guidance with practices and patterns for Office Add-in development

https://github.com/OfficeDev/PnP-OfficeAddins/

Samples

https://docs.microsoft.com/en-us/azure/active-directory/develop/sample-v2-code

https://github.com/Azure-Samples/

Calling an ASP.NET Core Web API from a WPF application using Azure AD V2

https://docs.microsoft.com/en-us/samples/azure-samples/active-directory-dotnet-webapp-webapi-openidconnect-aspnetcore/calling-a-web-api-in-an-aspnet-core-web-application-using-azure-ad/

https://docs.microsoft.com/en-us/samples/azure-samples/active-directory-dotnet-native-aspnetcore-v2/calling-an-aspnet-core-web-api-from-a-wpf-application-using-azure-ad-v2/

https://docs.microsoft.com/en-us/samples/azure-samples/active-directory-dotnetcore-console-up-v2/aad-username-password-graph/

https://github.com/Azure-Samples/active-directory-dotnet-webapp-openidconnect-aspnetcore

Web API calling a downstream API on behalf of the user using the Microsoft identity platform (formerly named Azure AD) v2.0 enpoint

https://github.com/Azure-Samples/ms-identity-aspnet-webapi-onbehalfof

Calling a ASP.NET Core Web API from a WPF application using Azure AD v2.0

https://github.com/Azure-Samples/active-directory-dotnet-native-aspnetcore-v2/

Office Add-ins platform overview

See also

https://docs.microsoft.com/en-us/office/dev/add-ins/overview/office-add-ins

Excel VBA delete row if contains certain strings

June 9, 2020 09:36

Excel VBA delete row if contains certain strings (edit)

https://excel.officetuts.net/en/vba/delete-a-row-if-cell-contains

https://analysistabs.com/vba/delete-row-if-cell-contains-string-excel-macro-example-code/

https://stackoverflow.com/questions/26683163/excel-vba-delete-row-if-contains-certain-strings-or-has-a-delete-flag-set

What is VBA?

The acronym VBA stands for Visual Basic for Applications. It is an integration of the Visual Basic with Microsoft Office applications (MS Excel, MS PowerPoint, MS Access, MS Word and MS Outlook). By running VBA within the Microsoft Office applications, you can automate repetitive tasks.

Getting Started With VBA

https://www.guru99.com/creating-your-first-visual-basic-for-applications-vba-in-excel.html

https://riptutorial.com/excel-vba

https://www.listendata.com/2014/05/excel-macro-beginner-tutorial-make-your.html

https://www.i-programmer.info/ebooks/automating-excel/1264-getting-started.html

Getting Started With VBA Automation

https://spreadsheet1.com/getting-started-with-vba.html

open Visual Basic Editor

Open The Visual Basic Editor

You can open the Visual Basic Editor (VBE) using the ALT-F11 shortcut or from the Developer Tab, click 'Visual Basic'

https://www.thespreadsheetguru.com/

https://www.ozgrid.com/forum/

http://excelexperts.com/forum

http://excelexperts.com/Free-Excel-Training-Videos

What are excel macros?

https://www.listendata.com/2014/05/excel-macro-beginner-tutorial-make-your.html

5 Different Ways to Find The Last Row or Last Column Using VBA

https://www.thespreadsheetguru.com/blog/2014/7/7/5-different-ways-to-find-the-last-row-or-last-column-using-vba

Copy & Paste Multiple Excel Ranges To Separate PowerPoint Slides With VBA

https://www.thespreadsheetguru.com/blog/2014/6/30/copy-paste-multiple-excel-ranges-to-separate-powerpoint-slides-with-vba

Code Sample

Giả sử cột A có những Row chứa chuỗi cần Delete cả dòng đó, ta thực hiện như sau:

  1. Press Alt + F11
  2. Go to menu Insert > Module
  3. Paste the following code
  4. F5 to delete entire row
Sub DeleteEntireRow()

Dim i As Long, searchString As String

For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1

searchString = LCase(Range("A" & i))

If (InStr(1, searchString, ".exe") > 0) Or _
(InStr(1, searchString, ".png") > 0) Or _
(InStr(1, searchString, ".jpg") > 0) Then
Rows(i).Delete
End If

NextRow:
Next i

End Sub

Categories

Recent posts