scm0094

Opening Excel via VBA loses DataLink

Discussion created by scm0094 on Jun 21, 2010
Latest reply on Jul 6, 2010 by mziegler

I have put together a toolbar for users to be able to click on buttons to open various items.  Some of these items are Excel workbooks.  The code below shows the code that I'm using to open the workbooks.  The two "Addins" lines in "Button1_Click" are a work around for an issue that I'm having.  Without these two lines Excel opens and the PI DataLink addin is selected, but there is no "PI" menu item and DataLink does not work.  I would like to remove the two "Addins" lines from the code and have Excel open correctly.  Any suggestions?  I'm using PI DataLink version 3.1.6, Microsoft Visual Basic version 6.5, and Microsoft Excel 2003 SP3.

Option Strict Off 
Imports Excel = Microsoft.Office.Interop.Excel
Imports Word = Microsoft.Office.Interop.Word
Imports System.IO

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
   Dim xlApp As Excel.Application
   xlApp = New Excel.ApplicationClass

   xlApp.Application.Workbooks.Open(Label1.Text)
   xlApp.Visible = True
   xlApp.AddIns("PI-DataLink").Installed = False
   xlApp.AddIns("PI-DataLink").Installed = True
End Sub 

Sub read_text()
   Dim line As String
   Using sr As StreamReader = New StreamReader(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\FileLocations.txt") 
      ' Read and display the lines from the file until the end of the file is reached.
      line = sr.ReadLine()
      Label1.Text = line
   End Using
End Sub 

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   Dim fso
   fso = CreateObject("Scripting.FileSystemObject")
   fso.CopyFile("R:\Duty_Scheduling\Toolbar\FileLocations.txt", Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\FileLocations.txt") 
   Call read_text()
End Sub

End Class

Outcomes