https://www.excelfox.com/forum/showthread.php/2348-String-text-in-Word-html-Passing-info-between-Word-and-Excel?p=15644&viewfull=1#post15644
We seem to have some inconstancy with the files and folders produced by the original OP macro, ( https://excelfox.com/forum/showthrea...ll=1#post15623 ) , and those in the last post, so I will look into that here.
The inconstancy seems to be that a .htm file was not produced by the original OP macro– instead some strange file was there , one with no extension shown, and the new file folder produced did not have the full name 2. KEEP DUPLICATE RECORDS-Files , instead it came out as 2-Files
2_ KEEP DUPLICATE RECORDS_docx gices these files when saved as _htm.JPG2_ KEEP DUPLICATE RECORDS_docx gives these files when saved as _htm.JPG
I had a little play around, and it looks I have tracked down the problem.
To demo:-
The following macro doers three Save As .htm code lines. The first does something similar to the original OP’s
The second has replaced the first _ . _ in the file name with a _ _ _
The final code line does the code line what the macro recorder gave.
Looking at the three results, it is obvious what’s probably going on: The missing .htm in the OP’s code line is causing the problem. Although we are saving as FileFormat:=wdFormatHTML , it gets no extension on the file name.
Without knowing exactly how Microsoft organised the working things, I cannot say exactly what is going on, but then file shown with no extension is clearly the htm file – we can prove this by opening with word, and it appears exactly the same as any of the 2. KEEP DUPLICATE RECORDS.htm files that we have been producing. The little discrepancy fact that the folder containing the images gets a name like 2-xxxx instead of like 2-2. KEEP DUPLICATE RECORDS xxxx , is probably because the workings are somehow mistaking the first _ . _ as the extension _ . _.
That discrepancy does not appear when we replace the _ . _ with some other character, as in the second Save As .htm code line
In fact, we also get a normal .htm extension as well. So this suggests that the workings are somehow confusing that first _ . _ as meaning that the extension is _ KEEP DUPLICATE RECORDS
So the conclusion is:
Most important you should add the .htm extension on the given file name.
It is probably good practice to not have an extra _ . _ in any file name
Results:
ActiveDocument.SaveAs FileName:=strPath & "Temp1" & "" & "2. KEEP DUPLICATE RECORDS", FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:= True
ActiveDocument.SaveAs FileName:=strPath & "Temp2" & "" & "2_ KEEP DUPLICATE RECORDS", FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False
ActiveDocument.SaveAs FileName:=TempFolder & "" & "2. KEEP DUPLICATE RECORDS.htm", FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False ', EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
Code:Sub OPsFileMakesStrangeFiles() ' https://excelfox.com/forum/showthread.php/2348-Just-Testing-Passing-info-between-Word-and-Excel?p=15644&viewfull=1#post15644 Dim strPath As String: Let strPath = "F:\Excel0202015Jan2016\ExcelFox\Word\prkhan56\" Documents.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\Word\prkhan56\2. KEEP DUPLICATE RECORDS.docx" ' This wont error if document file is already open If Dir(strPath & "Temp1", vbDirectory) = "" Then MkDir strPath & "Temp1" ActiveDocument.SaveAs Filename:=strPath & "Temp1" & "\" & "2. KEEP DUPLICATE RECORDS", FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=True ActiveDocument.Close Documents.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\Word\prkhan56\2. KEEP DUPLICATE RECORDS.docx" ' This wont error if document file is already open If Dir(strPath & "Temp2", vbDirectory) = "" Then MkDir strPath & "Temp2" ActiveDocument.SaveAs Filename:=strPath & "Temp2" & "\" & "2_ KEEP DUPLICATE RECORDS", FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False ActiveDocument.Close Documents.Open Filename:="F:\Excel0202015Jan2016\ExcelFox\Word\prkhan56\2. KEEP DUPLICATE RECORDS.docx" ' This wont error if document file is already open If Dir(strPath & "Temp3", vbDirectory) = "" Then MkDir strPath & "Temp3" ActiveDocument.SaveAs Filename:=TempFolder & "\" & "2. KEEP DUPLICATE RECORDS.htm", FileFormat:=wdFormatHTML, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False ', EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False ActiveDocument.Close End Sub







Reply With Quote





Bookmarks