Knowledgebase (2311)
Children categories
VBA (Visual Basic for Applications) macros are small programs that can be embedded within Microsoft Word documents to automate repetitive tasks, add interactivity to documents, and perform other useful functions. While macros can be beneficial in many situations, they can also pose a security risk if the code is malicious or contains malware. By removing VBA macros from Word documents, you can reduce the risk of security breaches and malware infections. In this article, you will learn how to detect and remove VBA macros from Word documents in C# and VB.NET using Spire.Doc for .NET library.
Install Spire.Doc for .NET
To begin with, you need to add the DLL files included in the Spire.Doc for .NET package as references in your .NET project. The DLL files can be either downloaded from this link or installed via NuGet.
PM> Install-Package Spire.Doc
Detect and Remove VBA Macros from Word Documents in C# and VB.NET
You can use the Document.IsContainMacro property to detect whether a Word document contains VBA macros. If any macros are detected, you can use the Document.ClearMacros() method to easily remove them from the document.
The following steps show how to detect and remove VBA macros from a Word document using Spire.Doc for .NET:
- Initialize an instance of the Document class.
- Load a Word document using the Document.LoadFromFile(string fileName) method.
- Detect if the document contains VBA macros using the Document.IsContainMacro property.
- If any macros are detected, remove them from the document using Document.ClearMacros() method.
- Save the result document using Document.SaveToFile(string fileName, FileFormat fileFormat) method.
- C#
- VB.NET
using Spire.Doc;
namespace RemoveVBAMacros
{
internal class Program
{
static void Main(string[] args)
{
//Initialize an instance of the Document class
Document document = new Document();
//Load a Word document
document.LoadFromFile("Input.docm");
//Detect if the document contains macros
if (document.IsContainMacro)
{
//Remove the macros from the document
document.ClearMacros();
}
//Save the result document
document.SaveToFile("RemoveMacros.docm", FileFormat.Docm);
document.Close();
}
}
}

Apply for a Temporary License
If you'd like to remove the evaluation message from the generated documents, or to get rid of the function limitations, please request a 30-day trial license for yourself.
Vary the Colors of Same-series Data Markers in a Chart in C#, VB.NET
2018-06-12 06:38:00 Written by KoohjiIf you have a line, (xy) scatter, or radar chart, you can change the look of the data markers to make them easier to distinguish. In this article, you will learn how to set different colors for different data markers, by using Spire.Presentation with C# and VB.NET.
Step 1: Load a sample PowerPoint file.
Presentation ppt = new Presentation();
ppt.LoadFromFile("ScatterChart.pptx");
Step 2: Get the chart from the presentation.
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
Step 3: Create a ChartDataPoint object and specify the index.
ChartDataPoint dataPoint = new ChartDataPoint(chart.Series[0]); dataPoint.Index = 0;
Step 4: Set the fill color of the data marker.
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid; dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Red;
Step 5: Set the line color of the data marker.
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid; dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Red;
Step 6: Add the data point to the point collection of a series.
chart.Series[0].DataPoints.Add(dataPoint);
Step 7: Save to file.
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
Source File:

Result:

Full Code:
Presentation ppt = new Presentation();
ppt.LoadFromFile("ScatterChart.pptx");
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
ChartDataPoint dataPoint = new ChartDataPoint(chart.Series[0]);
dataPoint.Index = 0;
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Red;
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Red;
chart.Series[0].DataPoints.Add(dataPoint);
dataPoint = new ChartDataPoint(chart.Series[0]);
dataPoint.Index = 1;
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Yellow;
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Yellow;
chart.Series[0].DataPoints.Add(dataPoint);
dataPoint = new ChartDataPoint(chart.Series[0]);
dataPoint.Index = 2;
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Blue;
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Blue;
chart.Series[0].DataPoints.Add(dataPoint);
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System.Drawing;
namespace VaryColor
{
class Program
{
static void Main(string[] args)
{
Presentation ppt = new Presentation();
ppt.LoadFromFile("ScatterChart.pptx");
IChart chart = ppt.Slides[0].Shapes[0] as IChart;
ChartDataPoint dataPoint = new ChartDataPoint(chart.Series[0]);
dataPoint.Index = 0;
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Red;
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Red;
chart.Series[0].DataPoints.Add(dataPoint);
dataPoint = new ChartDataPoint(chart.Series[0]);
dataPoint.Index = 1;
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Yellow;
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Yellow;
chart.Series[0].DataPoints.Add(dataPoint);
dataPoint = new ChartDataPoint(chart.Series[0]);
dataPoint.Index = 2;
dataPoint.MarkerFill.Fill.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Fill.SolidColor.Color = Color.Blue;
dataPoint.MarkerFill.Line.FillType = FillFormatType.Solid;
dataPoint.MarkerFill.Line.SolidFillColor.Color = Color.Blue;
chart.Series[0].DataPoints.Add(dataPoint);
ppt.SaveToFile("result.pptx", FileFormat.Pptx2010);
}
}
}
At some point, programmers may need to determine if an Excel file contains VBA macros. This article is going to show you how to programmatically determine if an Excel file contains VBA macros in C# and VB.NET using Spire.XLS.
Detail steps:
Step 1: Instantiate a Workbook object and load the Excel file.
Workbook workbook = new Workbook();
workbook.LoadFromFile("Macro.xlsm");
Step 2: Determine if the Excel file contains VBA macros.
bool hasMacros = false;
hasMacros = workbook.HasMacros;
if (hasMacros)
{
Console.WriteLine("The file contains VBA macros");
}
else
{
Console.WriteLine("The file doesn't contain VBA macros");
}
Screenshot:

Full code:
using System;
using Spire.Xls;
namespace Determine_if_Excel_file_contains_macros
{
class Program
{
static void Main(string[] args)
{
//Instantiate a Workbook object
Workbook workbook = new Workbook();
//Load the Excel file
workbook.LoadFromFile("Macro.xlsm");
bool hasMacros = false;
//Determine if the Excel file contains VBA macros
hasMacros = workbook.HasMacros;
if (hasMacros)
{
Console.WriteLine("The file contains VBA macros");
}
else
{
Console.WriteLine("The file doesn't contain VBA macros");
}
Console.ReadKey();
}
}
}
Imports System
Imports Spire.Xls
Namespace Determine_if_Excel_file_contains_macros
Class Program
Private Shared Sub Main(ByVal args As String())
Dim workbook As Workbook = New Workbook()
workbook.LoadFromFile("Macro.xlsm")
Dim hasMacros As Boolean = False
hasMacros = workbook.HasMacros
If hasMacros Then
Console.WriteLine("The file contains VBA macros")
Else
Console.WriteLine("The file doesn't contain VBA macros")
End If
Console.ReadKey()
End Sub
End Class
End Namespace