| | |
Save in MS Word
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 3
Reputation:
Solved Threads: 0
Hi,
Im saving a file in MS Word and when i open it it shows me message to convert the file
here is the code i am using
Public Sub SaveDocumentAfterValid()
Dim fs, f, fc, f1
Dim fbase, fsubfol, fsubfol2, fsubfol3, fsubfol4, fsubfol5, fsubfol6, fname As String
Dim fname1, fbase_1, fsubfol_1, fsubfol_2, fsubfol_3 As String
Dim FirstN As String
Dim LastN As String
Dim CTN As String
Dim strClName As String
Dim strUrgencyTemp As String
Dim strActivePrinter As String
Dim strPages As String
Dim boolPrintPage1 As Boolean
Dim intALoopCounter As Integer
Dim highestValue As Integer
Dim highestValue1 As Integer
Dim currentuser As String
FirstN = Left((Trim(ThisDocument.FormFields("PMIHEADFIRSTNAME").Result)), 11)
LastN = Trim(ThisDocument.FormFields("PMIHEADSURNAME").Result)
CTN = Trim(ThisDocument.FormFields("PMIHEADIN_NUM").Result)
currentuser = fOSUserName()
strClName = LastN & " " & FirstN
fbase = "C:\Documents and Settings\"
fsubfol = currentuser & "\"
fsubfol2 = "Application Data\"
fsubfol3 = "Wescom\"
fsubfol4 = "PCCP\"
fsubfol5 = "Data\"
fsubfol6 = "Work_In_Progress\"
fname = strUrgencyTemp & _
Replace(Space(2 - Len(Month(Now()) & "")) & Month(Now()), " ", "0") & _
Replace(Space(2 - Len(Day(Now()) & "")) & Day(Now()), " ", "0") & _
strUrgency & " " & _
strSite & " " & _
LastN & ", " & _
FirstN
Set fs = CreateObject("Scripting.FileSystemObject")
If (fs.FolderExists(fbase)) Then
If Not (fs.FolderExists(fbase & fsubfol)) Then
MkDir (fbase & fsubfol)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2)) Then
MkDir (fbase & fsubfol & fsubfol2)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6)
End If
End If
If (fs.FileExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6 & fname & ".tif")) Then
Set f = fs.GetFolder(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6)
Set fc = f.Files
highestValue = 0
For Each f1 In fc
If ((InStr(f1.Name, fname) > 0) And ((Len(f1.Name) - 4) > fname)) Then
If (((Len(f1.Name) - 4) = Len(fname)) And (highestValue = 0)) Then
highestValue = 1
Else
If (CInt(Right(Left(f1.Name, Len(f1.Name) - 4), (Len(f1.Name) - 4) - (Len(fname) + 1))) >= highestValue) Then
highestValue = CInt(Right(Left(f1.Name, Len(f1.Name) - 4), (Len(f1.Name) - 4) - (Len(fname) + 1))) + 1
End If
End If
End If
Next
fname = fname & "~" & highestValue & ".doc"
Else
fname = fname & ".doc"
End If
On Error GoTo waserror
'Save current printer
strActivePrinter = Application.ActivePrinter
'MsgBox "Here2"
'Use dialog so we do not change the system wide default printer
With Dialogs(wdDialogFilePrintSetup)
.Printer = "Microsoft Office Document Image Writer"
.DoNotSetAsSysDefault = True
.Execute
End With
'MsgBox "Here3.1"
strPages = "1"
Application.PrintOut Background:=False, Append:=False, _
Range:=wdPrintRangeOfPages, OutputFileName:=("C:\PMITEMP\" & fname), _
Item:=wdPrintDocumentContent, Copies:=1, Pages:=strPages, _
PageType:=wdPrintAllPages, PrintToFile:=True
fs.MoveFile Source:=("C:\PMITEMP\" & fname), Destination:=(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6 & fname)
'MsgBox "Here5"
'Reset printer
With Dialogs(wdDialogFilePrintSetup)
.Printer = strActivePrinter
.DoNotSetAsSysDefault = True
.Execute
End With
MsgBox (fsubfol & fsubfol2 & fname & " has been saved. The document and application will now be closed.")
ThisDocument.Close _
SaveChanges:=wdDoNotSaveChanges
waserror:
If Err.Number = 5152 Then
MsgBox (fbase & fsubfol & " does not exist. The document has not been saved. Please contact IT/IS for further assistance.")
Else
MsgBox ("Error " & Err.Number & " " & Err.Description)
End If
ThisDocument.Close _
SaveChanges:=wdDoNotSaveChanges
End Sub
Im saving a file in MS Word and when i open it it shows me message to convert the file
here is the code i am using
Public Sub SaveDocumentAfterValid()
Dim fs, f, fc, f1
Dim fbase, fsubfol, fsubfol2, fsubfol3, fsubfol4, fsubfol5, fsubfol6, fname As String
Dim fname1, fbase_1, fsubfol_1, fsubfol_2, fsubfol_3 As String
Dim FirstN As String
Dim LastN As String
Dim CTN As String
Dim strClName As String
Dim strUrgencyTemp As String
Dim strActivePrinter As String
Dim strPages As String
Dim boolPrintPage1 As Boolean
Dim intALoopCounter As Integer
Dim highestValue As Integer
Dim highestValue1 As Integer
Dim currentuser As String
FirstN = Left((Trim(ThisDocument.FormFields("PMIHEADFIRSTNAME").Result)), 11)
LastN = Trim(ThisDocument.FormFields("PMIHEADSURNAME").Result)
CTN = Trim(ThisDocument.FormFields("PMIHEADIN_NUM").Result)
currentuser = fOSUserName()
strClName = LastN & " " & FirstN
fbase = "C:\Documents and Settings\"
fsubfol = currentuser & "\"
fsubfol2 = "Application Data\"
fsubfol3 = "Wescom\"
fsubfol4 = "PCCP\"
fsubfol5 = "Data\"
fsubfol6 = "Work_In_Progress\"
fname = strUrgencyTemp & _
Replace(Space(2 - Len(Month(Now()) & "")) & Month(Now()), " ", "0") & _
Replace(Space(2 - Len(Day(Now()) & "")) & Day(Now()), " ", "0") & _
strUrgency & " " & _
strSite & " " & _
LastN & ", " & _
FirstN
Set fs = CreateObject("Scripting.FileSystemObject")
If (fs.FolderExists(fbase)) Then
If Not (fs.FolderExists(fbase & fsubfol)) Then
MkDir (fbase & fsubfol)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2)) Then
MkDir (fbase & fsubfol & fsubfol2)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5)
End If
If Not (fs.FolderExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6)) Then
MkDir (fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6)
End If
End If
If (fs.FileExists(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6 & fname & ".tif")) Then
Set f = fs.GetFolder(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6)
Set fc = f.Files
highestValue = 0
For Each f1 In fc
If ((InStr(f1.Name, fname) > 0) And ((Len(f1.Name) - 4) > fname)) Then
If (((Len(f1.Name) - 4) = Len(fname)) And (highestValue = 0)) Then
highestValue = 1
Else
If (CInt(Right(Left(f1.Name, Len(f1.Name) - 4), (Len(f1.Name) - 4) - (Len(fname) + 1))) >= highestValue) Then
highestValue = CInt(Right(Left(f1.Name, Len(f1.Name) - 4), (Len(f1.Name) - 4) - (Len(fname) + 1))) + 1
End If
End If
End If
Next
fname = fname & "~" & highestValue & ".doc"
Else
fname = fname & ".doc"
End If
On Error GoTo waserror
'Save current printer
strActivePrinter = Application.ActivePrinter
'MsgBox "Here2"
'Use dialog so we do not change the system wide default printer
With Dialogs(wdDialogFilePrintSetup)
.Printer = "Microsoft Office Document Image Writer"
.DoNotSetAsSysDefault = True
.Execute
End With
'MsgBox "Here3.1"
strPages = "1"
Application.PrintOut Background:=False, Append:=False, _
Range:=wdPrintRangeOfPages, OutputFileName:=("C:\PMITEMP\" & fname), _
Item:=wdPrintDocumentContent, Copies:=1, Pages:=strPages, _
PageType:=wdPrintAllPages, PrintToFile:=True
fs.MoveFile Source:=("C:\PMITEMP\" & fname), Destination:=(fbase & fsubfol & fsubfol2 & fsubfol3 & fsubfol4 & fsubfol5 & fsubfol6 & fname)
'MsgBox "Here5"
'Reset printer
With Dialogs(wdDialogFilePrintSetup)
.Printer = strActivePrinter
.DoNotSetAsSysDefault = True
.Execute
End With
MsgBox (fsubfol & fsubfol2 & fname & " has been saved. The document and application will now be closed.")
ThisDocument.Close _
SaveChanges:=wdDoNotSaveChanges
waserror:
If Err.Number = 5152 Then
MsgBox (fbase & fsubfol & " does not exist. The document has not been saved. Please contact IT/IS for further assistance.")
Else
MsgBox ("Error " & Err.Number & " " & Err.Description)
End If
ThisDocument.Close _
SaveChanges:=wdDoNotSaveChanges
End Sub
![]() |
Similar Threads
- how can i display the ms word document in asp page? (ASP)
- VBA to save word doc in new 2007 format? (Visual Basic 4 / 5 / 6)
- How to save a word document accepted from user in MS SQL? (JSP)
- Word documents and web page (HTML and CSS)
- html Image List with divs shows incorrectly when opened in word (HTML and CSS)
- view word/excel (PHP)
- need help on my code about word frequency counter (C++)
- Very Strange Word 2003 Problem (Windows Software)
- Trying to send appleworks doc in word format!! (OS X)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: is it possible to code a leech in vb 6.0
- Next Thread: getting condtional report on the basis of field
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows





