Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
lockematthewp
Creator II
Creator II

Import From Excel Macro

I am currently using the following macros to browse for a file and import it:

Sub BrowseFolder
	 Const OverWrite = True
	 Dim destpath,  srcFiles
     Set objShell = CreateObject("Shell.Application")
     Set objFolder = objShell.BrowseForFolder(0, "Example", 16384,"Computer")
       On Error Resume Next
           If objFolder Is Nothing Then
          Wscript.Quit
     End If

 	 ActiveDocument.Variables("vFileName").SetContent objFolder.title, true
	 ActiveDocument.Variables("vFolderName").SetContent objFolder.self.path, true    
 
End Sub





Sub Import

MsgBox "Importing... Press OK to Continue"

Name1 = ActiveDocument.Variables("vFolderName").GetContent.String

Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open _
    (Name1)

intRow = 2

Do Until objExcel.Cells(intRow,1).Value = ""

	Set var_TimeStamp = ActiveDocument.Variables("var_TimeStamp")
	Set var_TEST_NO = ActiveDocument.Variables("var_TEST_NO")

	var_TimeStamp = objExcel.Cells(intRow, 1).Value
	var_TEST_NO = objExcel.Cells(intRow, 2).Value
	
    SET Result = ActiveDocument.DynamicUpdateCommand ("INSERT INTO * (TimeStamp, TEST_NO) VALUES ('"&var_TimeStamp&"','"&var_TEST_NO&"')")
    
 	if Result = false then
  		MsgBox Result.ErrorMessage
	end if  
  
	intRow = intRow + 1
Loop

objExcel.Quit

 MsgBox "Import Complete"

End Sub

However, I am only able to import excel files that are .xlsx only. Is there a way to change it to allow for .csv as well?

Also, when someone else imports the same data as me, the date fields are seperated. For example, there are multiple 1/1/19 instead of only one. But on mine it combines them all. I would really appreciate any help.

0 Replies