Sto impazzendo da oltre 2 mesi e non riesco a risolvere questo problema :-(
Il mio problema č riuscire a far interagire Visual Basic con il web.
In pratica io utilizzo questo codice che ho provato e funziona correttamente :
codice:
Option Explicit
Private Enum InternalFileFormat
Word_File = 1
Excel_File = 2
Text_File = 3
End Enum
Private Sub ConvertFiles(FolderPath As String, FileFormat As InternalFileFormat, Optional FileNme As String)
'Il passaggio di FileName e' opzionale, se non
'viene passato il programma assume per default
'la modifica di tutti i tipi di documento supportati
'all'interno della directory passata in formato PDF
Dim InternalFormat As Byte
Dim strFileToConvert As String
Dim strFolder As String
Dim StrFileNme As String
Dim StrResult As String
strFolder = ""
InternalFormat = FileFormat
StrFileNme = FileNme
If FileNme = "" Or IsEmpty(FileNme) Then
'Conversione di tutti i files della directory
Select Case InternalFormat
Case Is = 1 'word files (tutti)
strFileToConvert = Dir(strFolder + "*.doc")
Case Is = 2 'excel files (tutti)
strFileToConvert = Dir(strFolder + "*.xls")
Case Is = 3 'text files (tutti)
strFileToConvert = Dir(strFolder + "*.txt")
End Select
While strFileToConvert <> "" 'loop sulla directory
' avvia il tentativo di conversione PDF
If (ConvertFile(strFolder + strFileToConvert, _
FileFormat) = False) Then
Exit Sub
End If
' prossimo file
strFileToConvert = Dir
Wend
Else
'Converte un solo file
Select Case InternalFormat
Case Is = 1 'word file (singolo)
StrResult = ConvertFile(strFolder + _
StrFileNme, Word_File)
Case Is = 2 'excel file (singolo)
StrResult = ConvertFile(strFolder + _
StrFileNme, Excel_File)
Case Is = 3 'text file (singolo)
StrResult = ConvertFile(strFolder + _
StrFileNme, Text_File)
End Select
End If
End Sub
Private Function ConvertFile(strSourceFileName As String, FileType As InternalFileFormat) As String
On Error GoTo ErrorHandler
Dim msWord As Word.Application
Set msWord = GetObject(Class:="Word.Application.8")
msWord.ActivePrinter = "Adobe PDF"
If FileType = Excel_File Then SendKeys "{~}"
msWord.Documents.Open strSourceFileName
If FileType = Excel_File Then SendKeys "{~}"
msWord.ActiveDocument.PrintOut
msWord.ActiveDocument.Close True
Set msWord = Nothing
ConvertFile = True
Exit Function
ErrorHandler:
If Err.Number = 429 Then
Set msWord = CreateObject("Word.Application.8")
Err.Clear
Resume
End If
If IsCriticalError Then
ConvertFile = False
Exit Function
Else
Resume
End If
End Function
Private Function IsCriticalError() As Boolean
Dim strErrorMessage As String
Dim strFileName As String
Dim intFileNo As Integer
Dim strErrDate As String
Dim strErrRef As String
'Gli errori verranno riportati in un file LOG
Select Case Err.Number
Case Else
strFileName = App.Path & "\PDFError.log"
intFileNo = FreeFile
Open strFileName For Append As #intFileNo
strErrDate = Format(Now, "mm/dd/yyyy, hh:mm:ss AM/PM")
strErrRef = Err.Number & " " & _
Err.Description & " source: " & Err.Source
Print #intFileNo, strErrDate
Print #intFileNo, strErrRef
Print #intFileNo, vbCrLf
Close #intFileNo
IsCriticalError = True
Exit Function
End Select
IsCriticalError = False
End Function
Public Function Convert()
Call ConvertFile("c:\1.doc", 1)
End Function
Quando lo seguo come exe standard va tutto ok e mi converte in pdf quando lo interfaccio con il web sotto forma di libreria non mi funziona pių ... caso assurdo č che non mi da nemmeno errore !