| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Excel interface, Asp and SQL Server
My older user interface was html's pages, now I use Ms Excel combined with Asp, and Asp with SQl Server.
The main concept is: In the "save event" of Excel Sheet (VBA), I call a procedure that execute a batch file with Ms-Dos commands to Load the Excel's workbook in my website via FTP, in the same "sub", i execute "shell function" to run the asp page to make transactions with my database. At the end I post the source code. Mi antigua interface de usuario fueron paginas html, ahora uso Ms Excel combinado con Asp, y Asp con Sql Server. El concepto principal es: en el evento "guardar" de la planilla excel (VBA), llamo al procediminto que ejecuta un archivo batch con comandos de Ms-Dos para cargar el libro de Excel en mi sitio via FTP, en el mismo "sub", ejecuto la funcion "shell" para correr la pagina asp que hace las transacciones con la base de datos. Al final posteo el codigo fuente. Source code / codigo fuente: Code:
'HERE I DECLARE AN API'S LIBRARIES TO DO SOME THINGS
'AQUI DECLARO LIBRERIAS API PARA HACER ALGUNAS COSAS.
'LIB TO MAKE DELAY INTERVALS OF EXECUTION
'LIB PARA HACER INTERVALOS RETARDO EN LA EJECUCION
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
'LIB TO FIND THE PATH OF A FILE, NECESARY TO KNOW WHERE IS IEXPLORE.EXE
'LIB PARA ENCONTRAR LA RUTA DE UN ARCHIVO, NECESARIA PARA SABER DONDE ESTA IEXPLORE.EXE
Private Declare Function apiSearchTreeForFile Lib "ImageHlp.dll" Alias _
"SearchTreeForFile" (ByVal lpRoot As String, ByVal lpInPath _
As String, ByVal lpOutPath As String) As Long
Function fSearchFile(ByVal strFilename As String, ByVal strSearchPath As String) As String
'THIS FUNCTION FIND THE FILE
'ESTA FUNCION ENCUENTRA EL ARCHIVO
Dim lpBuffer As String
Dim lngResult As Long
fSearchFile = ""
lpBuffer = String$(1024, 0)
lngResult = apiSearchTreeForFile(strSearchPath, strFilename, lpBuffer)
If lngResult <> 0 Then
If InStr(lpBuffer, vbNullChar) > 0 Then
fSearchFile = Left$(lpBuffer, InStr(lpBuffer, vbNullChar) - 1)
End If
End If
End Function
Sub SubirExcel()
'THE PROCEDURE NAMED "SubirExcel" (tr. UploadExcel) MAKE THE JOB
'EL PROCEDIMIENTO LLAMADO "SubirExcel", HACE EL TRABAJO.
'FIRST, SAVE THE EXCEL BOOK.
'PRIMERO, GUARDA EL LIBRO DE EXCEL.
ActiveWorkbook.Save
'SECOND, MAKE THE BATCH FILE WITH FTP COMANDS AND THE COMPLEMENTARY TEXT FILE WITH LOGIN INFO. ALL WITH FSO OBJECT.
'SEGUNDO, CREA EL ARCHIVO BATCH CON LOS COMANDOS FTP Y EL ARCHIVO COMPLEMENTARIO DE TEXTO CON LA INFORMACION DE AUTENTICACION. TODO CON EL OBJECTO FSO.
Dim ArchFtp
Dim Carpeta
Dim ArchLocal
Dim ArchLocales
Dim v_linea
Dim v_cont
Dim FSO As New FileSystemObject
Dim FSO2 As New FileSystemObject
Dim FSO3 As New FileSystemObject
v_host = "(URL address blocked: See forum rules)"
v_user = "myuser"
v_pwd = "mypwd"
v_mode = "binary" 'ascii/binary
v_origen = "C:\"
v_destino = "mydir/mysubdir/"
v_archftpmain = v_origen & "\ftpmain.bat"
v_archftplogin = v_origen & "\ftplogin.txt"
v_excel = "comercialinvoice.xls"
Set ArchFtpMain = FSO.OpenTextFile(v_archftpmain, 2, True)
ArchFtpMain.WriteLine ("call ftp -s:" & v_archftplogin & " " & v_host)
ArchFtpMain.Close
Set ArchFtpMain = Nothing
Set FSO = Nothing
Set ArchFtp = FSO2.OpenTextFile(v_archftplogin, 2, True)
Set Carpeta = FSO3.GetFolder(v_origen)
Set ArchLocales = Carpeta.Files
'THIRD, IF THE ACTIVE EXCEL SHEET IS "CLIENTS", I CHOOSE THE ASP PAGE "clients.asp" TO EXECUTE. THIS IS IMPORTANT, BECAUSE, THE ONLY THING TO DO THE USER IT'S CLICK THE BUTTON NAMED "SAVE" OR FILE MENU + SAVE.
'TERCERO, SI LA PLANILLA ACTIVA DE EXCEL ES "CLIENTES", SELECCIONO LA PAGINA ASP "clients.asp" PARA EJECUTARLA. ESTO ES IMPORTANTE, PORQUE, LO UNICO QUE HACE EL USUARIO ES HACER CLIC EN EL BOTON LLAMADO "GUARDAR" O EN EL MENU ARCHIVO + GUARDAR.
v_action = UCase(ActiveSheet.Name)
Select Case v_action
Case "CLIENTS", "CLIENTES"
v_pagina = "clients.asp"
Case "PRODUCTS", "PRODUCTOS"
v_pagina = "products.asp"
Case Else
v_pagina = "invoice.asp"
End Select
ArchFtp.WriteLine (v_user)
ArchFtp.WriteLine (v_pwd)
ArchFtp.WriteLine ("cd httpdocs/" & v_destino)
ArchFtp.WriteLine ("lcd " & v_origen)
ArchFtp.WriteLine ("put " & v_excel)
ArchFtp.WriteLine ("bye")
ArchFtp.Close
Set ArchLocal = Nothing
Set ArchLocales = Nothing
Set Carpeta = Nothing
Set ArchFtp = Nothing
Set FSO2 = Nothing
Set FSO3 = Nothing
xx = Shell(v_archftpmain, vbNormalFocus)
'FOURTH, SEARCH THE PATH OF IEXPLORE.EXE.
'CUARTO, BUSCO LA RUTA DE IEXPLORE.EXE
v_iexplore = fSearchFile("iexplore.exe", "C:\")
If v_pagina <> "" Then
v_web = v_iexplore & " (URL address blocked: See forum rules)" & v_pagina
Sleep (4000)
'FINALLY, I EXECUTE THE WEB BROWSER IN HIDE MODE TO RUN THE ASP PAGE.
'FINALMENTE, EJECUTO EL EXLORADOR WEB IN MODO OCULTO PARA CORRER LA PAGINA ASP.
xx = Shell(v_web, vbHide)
End If
End Sub
FEEL FREE TO USE THIS IDEA. BYE FRIENDS. SIENTANSE EN LIBERTAD DE USAR ESTA IDEA. CHAO AMIGOS. |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > Excel interface, Asp and SQL Server |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|