Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

lockematthewp
Contributor 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.