Hello, I am trying to write a simple program that will export embedded images from an MS-Word file and save it as an image on my machine (either tiff or jpeg). Is there an image object model built in that can extract this type of data? (Note: the Word file could be open or closed. It does not matter) Thanks Harry Wishes
Harold_Wishes
Posts
-
Exporting images from Office Applications -
Importing html code using HTMLProject object [modified]Hello I have extracted the html code from a web table embedded in a Word document and stored it in a variable string as shown below. The Word document is saved as an html page in Word.
Dim html_string as String
html_string = ActiveDocument.HTMLProject.HTMLProjectItems(1).Text
Selection.WholeStory
Selection.Delete Unit:=wdCharacter, count:=1
Selection.TypeText Text:=html_string '''LINE 5 is the problem lineIt works very well when I test the script on Word documents with small embedded html tables with few rows and columns but not everything gets stored for large tables beyond a certain number of rows and columns. The string gets truncated after some point. The truncation seems to take place when I execute line 5 above (Selection.TypeText Text:html_string). The "html_string" variable itself retains all of the html code when I throw it's output to the screen so I know for a fact something is happening when I place the contents into the active Word document using the Selection.TypeText method. Is there a character size limit when using the Selection.TypeText method? If so, is there a way around this? Thanks :cool: Harry Wishes
modified on Thursday, July 2, 2009 9:24 AM
-
Copy html with VBHello This may be trivial but I would like to automate a way of going to a particular web page and download that page to a local machine. Is there some sort of "save target as" feature to achieve this? :) Thanks HRW
-
Sending Email using VBA in WordHello, First, thanks for providing me this script. I ran it and everything seems to work fine until I run into the last line of code:
objEmail.Send
I get the following runtime error message:
Run-time error '-2147220975 (80040211)':
The message could not be sent to the SMTP server. The transport error code was 0x800ccc15. The server response was not available.I am surprised to get this message because Outlook is already set up so I can send and recieve messages. Any suggestions? Thanks again! :)
-
Sending Email using VBA in WordHello I would like to know if there is a programmatic way to send an email message to someone from VBA in Word 2003? After searching a bunch of online references, I know there is an OUTLOOK object reference available that can be added to an existing project and that you can create an instance of the Outlook application but I do not know where to go from here. Every Outlook programming book I've peeked thru only addresses things you can do in Outlook itself, not things involving other office applications. If I can invoke this Outlook task from Word, I will be much further ahead with my project. Everything else I have in my program works fine. Any help welcome. Thanks! :)
-
Adding Metadata Using Visual Basic 2008Hello, I have attached a VB program done in VB 2008 which adds annotations to an Acrobat PDF file specified by the user. So far, it works like a champ. However, my ultimate goal is to build a VB 2008 application that inserts metadata into the "Title", "Author", "Subject" and "Keywords" fields that are accessible from the Description tab of the Document Properties dialog box on the Acrobat "File" menu. I can do this in Acrobat's built-in JavaScript debugger just fine. For instance, the following will insert Harry Wishes into the author field.
this.info.author = "Harry Wishes"
My question: How do I invoke the Javascript object from Visual Basic 2008 that could access and modify this PDF metadata from Visual Basic? Help Apprectiated. Thanks! :)
Public Class Form1
Dim gApp As Acrobat.CAcroAppPrivate Sub Form1\_Load() gApp = CreateObject("AcroExch.App") End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pdDoc As Acrobat.CAcroPDDoc Dim page As Acrobat.CAcroPDPage Dim jso As Object Dim path As String Dim point(1) As Integer Dim popupRect(3) As Integer Dim pageRect As Object Dim annot As Object Dim props As Object OpenFileDialog1.ShowDialog() path = OpenFileDialog1.FileName pdDoc = CreateObject("AcroExch.PDDoc") If pdDoc.Open(path) Then jso = pdDoc.GetJSObject If Not jso Is Nothing Then ' Get size for page 0 and setup arrays page = pdDoc.AcquirePage(0) pageRect = page.GetSize point(0) = 0 point(1) = pageRect.y popupRect(0) = 0 popupRect(1) = pageRect.y - 100 popupRect(2) = 200 popupRect(3) = pageRect.y ' Create a new text annot annot = jso.AddAnnot props = annot.getProps props.Type = "Text" annot.setProps(props) ' Fill in a few fields props = annot.getProps props.page = 1 props.point = point props.popupRect = popupRect props.author = "Rob McAfee" props.noteIcon = "Comment" props.strokeColor = jso.Color.red pro
-
"Can not create ActiveX Component"Ahhh. I have only the Reader 8.0 on the machine I am testing. Thanks. :)
-
"Can not create ActiveX Component"Hello I am testing a VB 2008 application which will allow the user to select a PDF, add a pre-defined annotation, and save the file back to disk. That's all I want from the program at the moment. However, I get a runtime error when I try to create the AcroExch.App object so that my application can interact with Acrobat. I get the "Can not create ActiveX Component" exception handler on the screen when I try to debug or launch my application. Does anyone know what this means? I bolded the offending code below. Thanks! :)
Public Class Form1
Dim gApp As Acrobat.CAcroAppPrivate Sub Form\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load **gApp = CreateObject("AcroExch.App")** End Sub Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim pdDoc As Acrobat.CAcroPDDoc Dim page As Acrobat.CAcroPDPage Dim jso As Object Dim path As String Dim point(1) As Integer Dim popupRect(3) As Integer Dim pageRect As Object Dim annot As Object Dim props As Object OpenFileDialog1.ShowDialog() path = OpenFileDialog1.FileName pdDoc = CreateObject("AcroExch.PDDoc") If pdDoc.Open(path) Then jso = pdDoc.GetJSObject If Not jso Is Nothing Then ' Get size for page 0 and setup arrays page = pdDoc.AcquirePage(0) pageRect = page.GetSize point(0) = 0 point(1) = pageRect.y popupRect(0) = 0 popupRect(1) = pageRect.y - 100 popupRect(2) = 200 popupRect(3) = pageRect.y ' Create a new text annot annot = jso.AddAnnot props = annot.getProps props.Type = "Text" annot.setProps(props) ' Fill in a few fields props = annot.getProps props.page = 0 props.point = point props.popupRect = popupRect props.author = "Rob McAfee" props.noteIcon = "Comment" props.strokeColor = jso.Color.red props.Contents = "I added this comment from Visual Basic!" annot.setProps(props) pdDoc.Close() MsgBox("Annotation added to " &
-
Using "wdPropertyTimeLastSaved" fon Userforms for Word.Hello, This is perhaps not the best forum to post this but I've already posted to Microsoft's programming forum but have not recieved a reply. I have a question about the "wdPropertyTimeLastSaved" property in VBA for word. I have attached a userform with the following code in the initializing section of my project. The form is associated with a template that displays the form when the template is used. Essentially it displays text right on the form itself, containing the date that the template was last saved. It works great. However, there is a wrinkle in my design. Whenever, I make changes to either the template or the form, I am prompted each time I use my template, to save the template even though I did a save. I found a way around this problem, but I don't care for the solution. I must go into the VBA editor and run the form at least once and then save the associated template. That does the trick. No more prompts to save the template. However, I do not want casual users to have to go thru this extra work each time a change is made to the template and/or form. If you place this small snippet of code below in your own forms, you will know what I'm talking about. Any suggestions? Thanks. :) lblUFdate.Caption is an actual caption on my form which displays the date.
Private Sub UserForm_Initialize()
Dim SavedTime As Date
SavedTime = ThisDocument.BuiltInDocumentProperties( _
wdPropertyTimeLastSaved).Value
lblUFdate.Caption = "Last Updated " & Format(SavedTime, "dd-mmm-yyyy
HH:mm AM/PM")End Sub
-
Greek Characters [modified]Hello Can someone direct me to a resource where I can find the codes for the greek alphabet? I know from experience that the alphabet for greeks comes in more than one flavor. I only have one set of codes in a macro I have written for Word but I know that 2 more exist. The database I am working with will not accept greek characters so I must convert them to the english spelling before I import them. Currently, my macro will not catch greek characters from certain sources because I do not have an exhaustive list of greek codes. Below I have a find and replace for finding betas----ChrW(61538). That code won't find all symbols that look like the beta symbol since some sources have it encoded differently. I have searched in more references than I care to admit. Can anyone help. I just need a reference. Thanks :)
Selection.HomeKey Unit:=wdStory
With Selection.Find
.Text = ChrW(61538)
.Replacement.Text = ".beta."
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Selection.WholeStory
Selection.Font.Name = "Times New Roman"-- modified at 16:08 Wednesday 9th August, 2006
-
Find and replaceHello, This is partly an MS-Word question but I am using VB subroutines which is where my problem arises. I have created a find and replace script that uses wildcards to find a pattern throughout a Microsoft Word 2003 document and replace the pattern with itself but with a different font color. The find and replace portions both work great as I am recording the macro (finding all instances of the pattern and changing the color). However, when I go back and run the macro to test it, it only finds the first instance of my pattern. Word apparently does not have the ability to record finds for all instances of a pattern in one pass. I tried putting a EOF or LOF function to force the macro to run until the end of file is reached but I get caught in an endless loop and I have to shut down the application all together. Does anyone know of a way of performing this action. Below is my code without a loop where only the first instance of the pattern is found. Thanks
Sub test()
'
' test Macro
' Macro recorded 8/5/2006 by Harold Woodall
'
Selection.Find.ClearFormatting
For Counter = 1 To 500
With Selection.Find
.Text = "(\>[A-Z,a-z]{1,250}\<)"
.Replacement.Text = "\1"
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
With Selection.Font
.Name = "Times New Roman"
.Size = 12
.Bold = True
.Italic = False
.Underline = wdUnderlineNone
.UnderlineColor = wdColorAutomatic
.StrikeThrough = False
.DoubleStrikeThrough = False
.Outline = False
.Emboss = False
.Shadow = False
.Hidden = False
.SmallCaps = False
.AllCaps = False
.Color = wdColorBlue
.Engrave = False
.Superscript = False
.Subscript = False
.Spacing = 0
.Scaling = 100
.Position = 0
.Kerning = 0
.Animation = wdAnimationNone
End With
Next
End Sub -
Find Function? [modified]Hello, Could you clarify? I would like to remove the code below and have the loop stop when the last tilda is found. Currently I have it set to loop twenty times.
For Counter = 1 To 20
I know there is some boolean function for find, but I'm not getting the syntax correct.
-
Find Function? [modified]Hello, I am new to VB and need help on a specific question. I need to know if there is a find function in VB so that I can terminate a loop. Example, suppose I need to find all tildas (~) in a file from start to finish in MS-Word. I would like to use a find function (if it exist) in my test condition so that the program exits the loop when the last tilda is found. Below is a for loop that I hard coded to repeat so many times but I would prefer doing it a better way. Help is appreciated.
Sub test()
'
' test Macro
' Macro recorded 7/30/2006 by Harold-Wishes
'
Selection.Find.ClearFormatting
For Counter = 1 To 20With Selection.Find .Text = "'" .Replacement.Text = "'" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.TypeText Text:="'" Next
End Sub
-- modified at 7:36 Monday 31st July, 2006
-
Creating a counter [modified]I need some help creating an MS-Word counter macro as I'm not well versed in Visual Basic. I am trying to find a repeating XML tag pattern in an MS-Word file as shown below:
<subunit>
any text . . .
</subunit>What I need the macro to do is to attach a number to the tag and each time the tag is found, the number should increment by 1. See my desired output:
<subunit_1>
any text . . .
</subunit_1><subunit_2>
any text . . .
</subunit_2><subunit_3>
any text . . .
</subunit_3>Can such a macro be created in Word? I do have some experience editing macros in the VB editor but very limited. I might add that I already have a macro that duplicates an XML tag each time I run the macro but without the incrementing. Should I try to edit this current macro to get my desired output? Thanks Harold -- modified at 0:05 Wednesday 26th July, 2006
-
cin issues [modified]For some reason, this seems to work although I do not know why it should. "cin" does not account for spaces. I added strings with spaces and no troubles much to my surprise :^)
char buffer[501] = {0}; // buffer for input
cout << "Please enter the length of the protein sequence;
cin >> buffer;
cin.getline(buffer, 500, '\n');-- modified at 17:56 Monday 24th July, 2006 UPDATE: I see from the output 2 getlines are needed.
-
cin issues [modified]Regarding my first question, you're suggesting something like below:
char buffer[501] = {0}; // buffer for input
cout << "Please enter the length of the protein sequence for Subunit;
cin.getline(buffer, 500, '\n');
cin.getline(buffer, 500, '\n');I probably need to modify the above some since both getline functions are doing the same thing -- modified at 16:21 Monday 24th July, 2006
-
cin issues [modified]To Zac: My last response was just made to the other member (David_Crow) who provided some feedback, but I understand your point with the string datatype and will test this out. Thanks HRW. -- modified at 15:29 Monday 24th July, 2006
-
cin issues [modified]Although this did solve my original issue, it has caused 2 old problems to crop up again. 1) I want the user to be able to bypass keyboard entrys when they hit ENTER if they choose to skip a question. Now when I hit ENTER, the program will not let me go to the next cout prompt. It is waiting for something other than "\n" character. I believe this is why I used my getline implementation. 2)Also, if I type in something like "new terminal", such entrys delimited by a space seem to cause the next cin input to read in the second string. But I need to test the output some more with this second issue since I'm getting other strange results.
-
cin issues [modified]The compiler is not giving me an error per se. It's building the executable. But, when I run the executable, I am prompted to enter data in sequence with a series of multiple cout prompts and cin inputs. I have no problems when I am doing this in the first function call. But when main() makes a call to function 2 after function 1 terminates, the very first cin input in function 2 seems to get skipped (at least that is what the debugger is showing me). It does not recognize it). The debugger moves right to the next cout prompt. :( If I remember correctly, I took this out of functions and slapped it out all in main() without any troubles.
-
Passing a variableIf I understand correctly, you are using a test condition for the following:
if (a = 1) dwID = IDC_EDIT1;
if (a = 2) dwID = IDC_EDIT2;
if (a = 3) dwID = IDC_EDIT3;If that is the case, you should be using the == operator instead of the = operator. if (a == 1) dwID = IDC_EDIT1; if (a == 2) dwID = IDC_EDIT2; if (a == 3) dwID = IDC_EDIT3; It's pretty easy to confuse the assignment operator with the equals operator which is 2 consecutive equal signs. :) -- modified at 13:27 Monday 24th July, 2006