Technology Software

How to Copy to Clipboard in Microsoft Visual Basic

    • 1). Type the following code in a new subroutine in your VB.NET project to declare your Excel variables:

      Dim XLApp As Microsoft.Office.Interop.Excel.Application = Nothing

      Dim XLBooks As Microsoft.Office.Interop.Excel.Workbooks = Nothing

      Dim XLBook As Microsoft.Office.Interop.Excel.Workbook = Nothing

      Dim XLSheets As Microsoft.Office.Interop.Excel.Sheets = Nothing

      Dim XLSheet As Microsoft.Office.Interop.Excel.Worksheet = Nothing

    • 2). Type the following to add a string of text to the clipboard and get the text from the clipboard:

      Dim processObject As New Process

      Clipboard.SetDataObject("This is copied to clipboard and added to Excel.")

      Dim clipboardObject As IDataObject = Clipboard.GetDataObject()

    • 3). Type the following to open Excel and add a new worksheet:

      XLApp = New Microsoft.Office.Interop.Excel.Application

      XLApp.Visible = True

      XLApp.DisplayAlerts = False

      XLBook = CType(XLApp.Workbooks.Add(), Microsoft.Office.Interop.Excel.Workbook)

      XLBooks = XLApp.Workbooks

      XLSheet = CType(XLBooks(1).Sheets.Item(1), Microsoft.Office.Interop.Excel.Worksheet)

      XLSheets = XLBook.Worksheets

    • 4). Type the following to add the string from the clipboard to Excel:

      With clipboardObject

      If .GetDataPresent(DataFormats.Text) Then

      XLSheet.Cells(1, 1) = .GetData(DataFormats.Text)

      End If

      End With

    • 5). Run your program.

Related posts "Technology : Software"

How to Put My FB to Sleep

Software

Some Useful Tips to Avoid Hack Attacks

Software

CREN

Software

How to Transfer DVD to 3GP

Software

How to Troubleshoot if My Computer Only Types in Wingdings

Software

What Cloud Computing Really Means

Software

How to Make More Points Visible on Scatter Plots in Excel for Mac

Software

How to Make a Spreadsheet Without Excel

Software

Enhancing VOB Videos to MPEG Format

Software

Leave a Comment