How can I create and edit a worksheet in MapViewer using automation?

This article contains a sample script for creating and editing a worksheet.

To run this script:

  1. Copy the script below, or click here to download the BAS file: Worksheet.BAS.
  2. In a Windows Explorer window, navigate to C:\Program Files\Golden Software\MapViewer 8\Scripter.
  3. Double click on Scripter.exe to launch Scripter.
  4. Press Ctrl+A to select all of the existing lines then press Delete.
  5. If you copied this script, press Ctrl+V to paste it into Scripter. If you downloaded it, click File | Open, select the BAS file from your downloads directory, and click Open.
  6. Click Script | Run to run the script.


' Worksheet.BAS
' Copyright (C) Golden Software Inc. 1992-2015
' This sample demonstrates how to to create worksheet.

Sub Main
   'Creates an instance of the MapViewer Application object
   ' and assigns it to the variable named "MapViewerApp"
   Set MapViewerApp = CreateObject("MapViewer.Application")

   'Makes the application main window visible
   MapViewerApp.Visible = True

   'Creates a worksheet document object, and assigns it to the variable named "doc"
   Set doc = MapViewerApp.Documents.Add(DocType:=mvDocWks)

   'Add some data to the worksheet document
   doc.Cells("A3").Value = 1
   doc.Cells("A4").Value = 2
   doc.Cells("A5").Value = 3
   doc.Cells("B3").Value = 4
   doc.Cells("B4").Value = 5
   doc.Cells("B5").Value = 6

   'Assigns the Windows list associated with this document to the variable named "WksWindows"
   Set WksWindows = doc.Windows

   'Assigns the first window in the Windows list to the variable named "win"
   Set win = WksWindows(1)

   'Makes "A3" cell active
   win.ActiveCell = "A3"
   If win.ActiveCell.Name <> "A3:A3" Then Stop

   'Selects cells A3 through A5
   win.Selection = "A3:A5"
   If win.Selection.Name <> "A3:A5" Then Stop

   'Checks Caption
   If win.Caption <> "Sheet1" Then Stop


End Sub


Updated November 2, 2016

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Please sign in to leave a comment.