Use Macro To Find A Specific Word In Excel
Hi all,
I need the help as currently i have created a vb program which link to excel worksheet. The program has to search for example "FREIGHT" word in EXCEL column B. If the column B has such "FREIGHT" wording, the program should stamp "FOUND" in column C else nothing will stamp in column c. I can use below script to find the "FREIGHT", but my question is how to set "FOUND" in column C if the "FREIGHT" wording is found in column b? Anybody got any clue on it ?
ExcelSheet.Columns.Find(What:="FREIGHT", After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False).Activate
Please help! Thanks!
From, Siaw Ch'ng
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Find Macro Or Open Find "find' In Excel Form
How can I make a macro or what is the code to open and use the "find" in excel using a form. I tried to record the macro opening the Edit then Find. Please fully explain if possible.
Thanks in advance.
Find A Specific Word From Word Document...
Hi All,
Need help...
i have a word doc. it contains some data.. and bottom of the page it contain the following paragraphs. its single page word doc.
Code:Very truly yours,
sam
Officer
From vb i want to find word, the next line of the 'very truely yours'. like here in this example i have to capture the value 'sam'.
Any idea how to get that..
Thanks
Balakumar
Edited by - pmmbala1976 on 6/2/2004 4:45:19 PM
Find A Specific Letter In A Word
I need to know if there is any sort of Visual Basic equivalent to the Javascript CharAt() function.
It's for a hangman game. I need to be able to get the length of the word too - that's another thing I can't do!
Thanks in advance...
How To Find A Specific Word In A Variable?
I need a simple way to do this..
(like the indexof(blah) in ASP / java)
if i have the variable "MSG this message"
how can i make it find the "MSG" part in that variable.
and if there is a "MSG" part in the variable, how can i make it read only what is behind the MSG part...
So that i can use this as a "command" in a text based program.
like if i write "MSG whatever text there is to write" into a variable (textbox) then it sees the MSG and takes the rest and produces
MSGBOX "whatever text there is to write",,"MSG command"
How can i do this? ?!?!?
Please provide whatever example you might have on this...
Thanks... in advance -AlexData-
Openning Excel And Running Macro From Word - Macro
Ok - I have a DB which I export to Excel, I then run a macro to "Groom The Data". I then run word and run a Macro (MailMerge to print labels) which retrieves data from the excel spreadsheet groomed above. Everything is working fine, despite my novice knowledge of VB, but I would like to do this in a single click.
I use a command line shortcut to Launch word and automatically have it run the macro, but I still have to Launch Excel and manually run its macro first.
I did not find a command line switch to make excel launch and run a macro. Is there any way I can Lauch Word have its Macro link to excel, then launch and run the excel macros before performing the macro I have set up in word (mailmerge)
In Other Words I have working macros in Word and Excel, I want the Word Macro to force the Excel macro to run before completing the rest of its duties.
Thanks
WW
How Do I Find A Specific Word Or Number Inside A Text Box
How do i find a specific word or number in a text box and then maybe replace it.
e.g.
the text box contains "This is a test"
I want to find "is" and replace it with "was"
also the text that is in the text box is text that is entered so I don't know what the text is when I make the program.
Thanks in advance.
How To Find A Button Based On Its Text , A Specific Word??
hii community,
i've been trying for this for last 1 week. now i'm able to do it in diffent fashion (using sendkeys etc..) but that is not efficient. So i want to follow a general procedure. Fot that i need to do the following.
how to find a button in a webpage based on its text , a specific word (this word may be a link to another page) in a webpage like ' compose', 'sentmail' etc. And perform the click operation . I can do it myself. All i want to know is how to find either a button or a specific word??
Please help me.
thanks.
Macro For Excel To Copy Data To Specific Worksheet - Help!
I need help creating a macro for Excel. My workbook has 13 worksheets in it. The first worksheet is for data entry - where the user types in the call information. Each of the other 12 worksheets are labeled by month. What I want is a macro that will copy the row of data (record) onto the corresponding month's worksheet.
For example, a call comes in on January 3, 2002. The employee puts in the date of the call, the problem and the solution in adjacent cells in the same row. I want a Macro to automatically copy that row's data onto the January worksheet, in the first empty row.
Any ideas?
Thanks!
Beth
Find Next Macro For Word
One thing about MS Word drives me crazy. Well, lots of things, but this one is particularly maddening.
In every other Windows text editing program, the [F3] key is "find next.' Once you've done a search, you can hit [F3] to step through the file, repeating the Find. It works in WordPad. In Notepad. It works in MS-DOS Edit. Probably worked in WordStar. Heck, my Linux editors have this feature.
Not MS Word. Its default F3 function is some obscure thing I've never used, never will. I think you need a three-handed function to evoke a Find Next.
What would be the most efficient macro to assign to F3 to execute a Find Next? I have some ideas, but I'll bet it's a one-liner.
Use Excel Macro To Delete Rows With Specific Data In Cells
I need some help writing a macro that deletes a row (or number of rows) in a worksheet. We have an appointment scheduling app that exports the data in .CSV format. I run a macro that formats this .CSV file so we can insert it into another .XLS sheet that gets emailed to our retail locations to post their daily appointments. What I would like to automate is removing multiple rows that have N A in the firstname & lastname columns. Is there someway to "delete any row that has N in column c and A in column d"? We use the N A as fake names to fill in time slots we don't want to make "real" appointments. Now I have those times blocked out and have to manually delete each one before copying into the formatted worksheet that's mailed to the individual stores. Thanks for any and all help! TommyT.
How To Find A Specific Instance Of Excel From VB6?
I've written a dictator application in VBA which is launched from an .exe. How do I test all instances of Excel running to see which is my application? (I could, for example, set a tag on the Excel.Application but I don't know how to run through in the VB6 frontloader all running instances of Excel to find it.). Any ideas?
Word Macro + Find/Replace + VBScript
Below is the code that i wrote to open a file, find some text, replace it and save the file under a different name, however it doesn't work properly, can anyone please help in fixing this problem. Thank you
Dim W
Set W = CreateObject("Word.Application")
set doc = W.Documents.Add
w.Documents.Open "c:PaymentLetter.dot"
w.Visible = True
With w.Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "##brk_st_nm##"
.Replacement.Text = "igor"
.Text="##MgmtFee##"
.Replacement.Text = "Hello"
.Forward = True
.Wrap=wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
w.Selection.Find.Execute
' Save the document.
doc.SaveAs "c:PaymentLetter1.doc"
' Quit Word.
' w.Quit
' Clear the variable from memory.
' Set w = Nothing
Word VBA/Macro To Find All Non-ascii/non-ansi Characters...?
Hi all,
I am trying to find a way to identify all of the Japanese, non-ascii, non-ansi characters (excluding formatting marks) in a Word document.
I work in the document translation business (I proofread documents that have been translated, Japanese -> English) and find that oftentimes our translators leave a few, stray double-byte characters in the text (I'm only worried about full-width/zenkaku characters as opposed to hankaku characters).
I need to have a quick way of searching through a Word doc (we use Office XP) to find and highlight these characters so I can then go through and change them to their single-byte equivalents.
So far I have tried creating a macro to check each individual word by comparing its byte-length before, and after, converting it to double-byte Unicode (i.e. if the size is the same before and after, then I know I found a double-byte word). However, needless to say, THIS IS TOO SLOW (the average document is anywhere from 50,000 to 150,000+ words)!
I have also tried using the built-in Find function with the following wildcard string which searches for characters that are NOT ascii:
[!^0013-^0255^t^m^x^z^l^n^11@* ]*
However, for some reason if there is a table, the Find function stops at the end of each cell, just before what looks like a carriage return (it's not a regular return because those are successfully ignored throughout the rest of the document. Also, Word doesn't highlight the character itself: the cursor simply stops there and there is nothing visibly highlighted). It must be stopping because of some zero-width or hidden character. I have set the options to show all formatting marks, print and web layout options, etc. Simply hiding all formatting marks doesn't cut it: it stops at the same places either way.
Once I find a regex that works, then I'll record a macro to automate the process more, but right now, I'm still missing a piece or two.
Having said all this, I am still open to other possibilities:
For example, the Word Count function (Tools > Word Count...) displays a value for 'Asian characters, Korean words'. Does anyone know how this value is calculated? Can it be calculated/accessed via VB/VBA somehow?, etc.
Any help would be appreciated. I apologize for the long post, but being new to this forum I don't want you to think that I don't "do my homework" before posting...
MLG
Word Macro Help: Selection.Find.Execute And File Input
I'm writing a macro to take input from a .txt file wordlist into a string variable, search the document for instances of that word, and mark each instance as an index entry. The code I came up with is as follows, using the variable "term" as the term to be marked:
Code:
With Selection.Find
.Text = term
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
ActiveWindow.ActivePane.View.ShowAll = True
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, Entry:= _
term, EntryAutoText:=term, CrossReference:="", _
CrossReferenceAutoText:="", BookmarkName:="", Bold:=False, Italic:=False
End If
The trouble is that this only marks the first instance of each term in the document. How would I go about having it scan the entire document and mark each instance of the term?
While I'm at it, I have another stupid question for you (it's been forever since I've written vb code). Let's say my wordlist file, which is parsed by commas, is opened for input as #1, and I want to input it into dynamic string array "term(x)". How would I go about defining x as the number of terms in the wordlist, then inputting the wordlist into the array from 1 to x sequentially? In other words, I want to count the number of terms in the list, assign that to a variable, and then input the terms from the file into an array.
Your help is appreciated. Thanks!
Word Macro: Selection.Find.Execute And File Input
I'm writing a macro to take input from a .txt file wordlist into a string variable, search the document for instances of that word, and mark each instance as an index entry. The code I came up with is as follows, using the variable "term" as the term to be marked:
CODEWith Selection.Find
.Text = term
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
If Selection.Find.Found Then
ActiveWindow.ActivePane.View.ShowAll = True
ActiveDocument.Indexes.MarkEntry Range:=Selection.Range, Entry:= _
term, EntryAutoText:=term, CrossReference:="", _
CrossReferenceAutoText:="", BookmarkName:="", Bold:=False, Italic:=False
End If
VB Can't Find Excel Macro
The following code fails with an error 1004 macro Translate_CSI_and_Create_Chart cannot be found. Everything else works, with the exception of the xlApp.Run command. The object definitions are in a separate module and are defined as follows:
'======================================================+
' Object Definitions |
'======================================================+
Public xlApp As Excel.Application
Public xlBook As Excel.Workbook
Public xlMacros As Excel.Workbook ' Personal.xls macro workbook
Public xlBooks As Excel.Workbooks
Public xlsheet As Excel.Worksheet
The following locations are correct in the program since they were copied via CTRL-C from Windows explorer and Excel respectively.
Path:C:Program FilesMicrosoft OfficeOfficeXLStartPersonal.xls
Macro Name:Translate_CSI_and_Create_Chart
Can you shed any light on this? I had it working at one point, but had to rebuild my C drive after a crash and it has failed consistently since then. I have tried both the entire path name and just the macro name in the variable str_Macro_Executed without success. I am running the Office97 suite under Windows 98. All patches have been applied. Thanks for your time.
Dim int_Counter As Integer
Dim str_Select_Statement As String ' save area for original select statement
Dim str_New_Select_Statement As String ' area for new select statement
Dim str_Select_Clause As String
Dim str_Order_By_Clause As String
Dim str_Where_Clause As String
Dim str_From As String
Dim str_To As String
Dim lng_Rcd_Ct As Long
Dim lng_Progress As Long
Dim lng_Len As Long
Dim int_File_Year As Integer
Dim str_File_Month As String
Dim int_Str_Len As Integer
Dim str_Macro_Workbook As String
Dim str_Macro_Executed As Variant
Dim str_Limit As String ' format yyyym All contract dates
' must be > than this
Dim str_Contract_Year_and_Month As String ' format yyyym as above
Const str_Quote As String = """"
Const cstr_Select_Clause As String = "SELECT * FROM 15_Mass_Update_File "
Const cstr_Where_Clause As String = " WHERE fld_Update_Name = "
Const cstr_Order_By_Clause As String = " ORDER BY fld_Update_Name"
On Error GoTo Error_Handler
' The following variable is the lower limit for analyzing contract prices
' All contract dates must be greater than this
str_Limit = Trim(gstr_Current_Year) & LCase(gstr_Current_Month)
str_Macro_Workbook = Trim(upr.str_Macro_Path) & "" & _
Trim(upr.str_Macro_Workbook)
str_Macro_Executed = Trim(upr.STR_MACRO_NAME)
Set xlMacros = GetObject(str_Macro_Workbook)
Do While lst_Update_Names.ListCount <> 0
lst_Update_Names.RemoveItem (0)
' Build Select statement with Update name
str_Select_Clause = cstr_Select_Clause
str_Order_By_Clause = cstr_Order_By_Clause
str_Where_Clause = cstr_Where_Clause & str_Quote & _
lst_Update_Names.List(0) & str_Quote
str_New_Select_Statement = str_Select_Clause & _
str_Where_Clause & _
str_Order_By_Clause
Adodc1_Mu.RecordSource = str_New_Select_Statement
Adodc1_Mu.Refresh
lng_Rcd_Ct = Adodc1_Mu.Recordset.RecordCount
prg_Mu.Max = lng_Rcd_Ct ' Progress bar record set size
Do While Adodc1_Mu.Recordset.EOF = False
str_From = txt_From_Path.Text
str_To = txt_To_Path.Text
str_Workbook_Name = txt_File_Name.Text
int_Str_Len = InStrRev(str_Workbook_Name, ".", -1) - 1
str_Worksheet_Name = Left(str_Workbook_Name, int_Str_Len)
' String contract yr & mo together for comparison to str_Limit
str_Contract_Year_and_Month = _
Adodc1_Mu.Recordset.Fields("fld_Contract_Year") & _
LCase(Adodc1_Mu.Recordset.Fields("fld_Contract_Month"))
If str_Contract_Year_and_Month > str_Limit _
Then
Set xlBook = xlApp.Workbooks.Open(str_To)
Adodc1_Mu.Recordset.MoveNext
Else
Adodc1_Mu.Recordset.MoveNext
End If
Loop
' Now that all the proper workbooks are open, run the analysis macro
xlApp.Visible = True
' Set xlsheet = xlBook.Worksheets(str_Worksheet_Name)
xlApp.DisplayAlerts = False
Set xlMacros = xlApp.Workbooks.Open(str_Macro_Workbook)
xlApp.Run (str_Macro_Executed)
xlApp.DisplayAlerts = True
DoEvents
Loop
Exit Sub
Error_Handler:
Find Macro In Excel
Hi Guys,
I am trying to Find a record and perform an action.
I am having a problem.
If the value is found the requeired action is performed
If the value is not found it gives an error msg.
==========================================================
The code I am writing is :
==========================================================
If Cells.Find(What:="abhatnagar", After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate Then
Range("G5").Select
ActiveCell.FormulaR1C1 = "Arpit"
Range("A1").Select
ElseIf Cells.Find("anukumar", ActiveCell, xlFormulas, xlPart, xlByRows, xlNext, False, False).Activate Then
Range("G6").Select
ActiveCell.FormulaR1C1 = "Anubhav"
Range("A1").Select
End If
==========================================================
Now if abhatnagar is not found , the program does not proceed to the ElseIf Statement and gives an error msg.
The record abhatnagar does not exist in the sheet.
The record anukumar does exist in the sheet.
Help would be really appreciated.
Help With A 'Find' Macro In MS Excel
I am trying to search for a particular value in one worksheet (A)of a spreadsheet. The value that I am searching is the value in a cell in a separate worksheet (B) in the same spreadsheet. After identifying that particular cell in worksheet (A), I want to select the cell next to it and paste some data (that I previously copied from (B))in it.
How do I set up the find function/macro to do that?
Please help/advise!
Thanks!
Archit
Excel Macro - FIND && PASTE
In Excel, i need to write some code that will search for something specific (let's say a cell containing the word EGG) Then copy some info from elsewhere (let's say the contents of cell A1) & paste it in to the cell below the "EGG" cell.
Sorry if the answer to this may be a long winded one, having a nightmare getting to grips with the whole FIND thing!
Thank you very much.
God, hopefully one day i'll have a quarter of the knowledge you lot hold!!!!!
VB6 Unable To Find Excel Macro
My object definitions are kept in a separate module and are:
'======================================================+
' Excel Object Definitions |
'======================================================+
Code:
Public xlApp As New Excel.Application
Public xlBook As New Excel.Workbook
Public xlMacros As New Excel.Workbook ' Personal.xls macro workbook
Public xlBooks As Excel.Workbooks
Public xlsheet As New Excel.Worksheet
Public xlSheets As Excel.Worksheets
In the Module that calls Excel I have:
'======================================================+
' String Variables |
'======================================================+
Code:
Dim str_Select_Statement As String ' save area for original select statement
Dim str_New_Select_Statement As String ' area for new select statement
Dim str_Select_Clause As String
Dim str_Order_By_Clause As String
Dim str_Where_Clause As String
Dim str_From As String
Dim str_To As String
Dim str_File_Month As String
Dim str_Limit As String ' format yyyym All contract dates
' must be > than this
Dim str_Contract_Year_and_Month As String ' format yyyym as above
'======================================================+
' Variant Variables |
'======================================================+
Code:
Dim vstr_Macro_Workbook As Variant
Dim vstr_Macro_Path As Variant
Dim vstr_Macro_Workbook_and_Path As Variant
Dim vstr_Macro_Executed As Variant
The following code builds a path to the Personal.xls work book:
Code:
' Get workbook name (e.g. personal.xls)
gstr_Macro_Workbook = Trim(gstr_Macro_Workbook)
' Get workbook path
gstr_Macro_Path = Trim(gstr_Macro_Path)
' Then concatenate the two
vstr_Macro_Workbook_and_Path = gstr_Macro_Path & "" & gstr_Macro_Workbook
vstr_Macro_Executed = Trim(gSTR_MACRO_NAME)
vstr_Macro_Executed = vstr_Macro_Workbook_and_Path & "!" & vstr_Macro_Executed
The following code builds a path to the Personal.xls work book:
Code:
' Get workbook name (e.g. personal.xls)
gstr_Macro_Workbook = Trim(gstr_Macro_Workbook)
' Get workbook path
gstr_Macro_Path = Trim(gstr_Macro_Path)
' Then concatenate the two
vstr_Macro_Workbook_and_Path = gstr_Macro_Path & "" & gstr_Macro_Workbook
vstr_Macro_Executed = Trim(gSTR_MACRO_NAME)
vstr_Macro_Executed = vstr_Macro_Workbook_and_Path & "!" & vstr_Macro_Executed
A bunch of code that opens the correct workbooks then:
xlApp.Run vstr_Macro_Executed
Which is the line that fails. I generate the error message dialog box with the message:
The macro 'C:Program FilesMicrosoft OfficeOfficeXLStartPersonal.xls!Translate_CSI_and_Create_Chart' cannot be found..
Microsoft Error = 1004 Microsoft Excel
I generate this message in the usual way (ERR.property), but this seems to be saying that Excel can't find it's own macro, even though it's in exactly the place specified. The module and macro names are the same, so I shouldn't have to bother with the Module name.Subroutine name syntax.
I converted to Windows 2000 Professional to avoid this, which drove me nuts in Win98, but here we are again.
Could this have something to do with which directory is the current one? All my VB6 stuff is in a directory separate from Excel. W2K has a bunch of XLSTART directories and that might upset things too. Currently, I do all my programming as Administrator.
Anyone have any ideas. Much more of this and I'll run screaming into the street.
By the way, Visual Studio 6.0 was installed fresh and W2K was installed on a bare drive. So I don't think anything on the drive did any damage.
Excel Macro For Find/Replace
Hi there. I wrote a macro for my excel spreadsheet to find and replace country codes. For example, I get a speadsheet from our manufacturing team. DE is the country code for Germany, AU is Australia, etc. I got the first one (Germany) to work, but it doesn't do any more than that. Below is my code. What am I doing wrong?
Sub ReplaceDE()
Dim rFound As Range
Dim szFirst As String
Dim iCount As Integer
ThisWorkbook.Worksheets(1).Activate
Set rFound = Columns(19).Find("DE")
iCount = 0
Do While Not rFound Is Nothing
''' Store address of first occurrence
If szFirst = "" Then
szFirst = rFound.Address
ElseIf rFound.Address = szFirst Then
Exit Do ''' If we have looped around, quit
End If
rFound.Value = Application.Substitute(rFound.Value, _
"DE", "Germany")
iCount = iCount + 1
Set rFound = Columns(19).Cells.FindNext(rFound)
Loop
MsgBox "Replaced occurrences in " & iCount & " cells."
End Sub
Then after the find/replace, I also need to split the countries into 4 different sheets within the same workbook. I need an Americas, Asia, Europe and Misc. sheets. How can I do that?
Muchas Gracias!
VB6.0: Find Excel Sheet With Macro
I am trying to build a small Visual Basic application (VB6.0) that will loop through a folder and pick out all the Excel files.
My question is--How can I programmatically tell if a particular Excel file contain Macro?
Please help me out.
Thanks in advance.
Excel Macro To Find And Reolace
hey guys ,
what is the procedure in vb 1.) in order to write a find and replace macro for a column(field name) and 2.) another macro to set the format(datatype) for each column. In my case I will be using type general, date in format xx/xx/xx xx:xx , and number with 2 decimal places.
Thanks guys
Inserting Specific Excel Table Into Word
Hello,
I'm new to the VBA stuff, done a little VB6.0 but here is my question. I want to create a table in Word by clicking a button(that I will make and insert into a tool bar). The idea is that when a user is typing along and wants to make a certain style table he will go and click this button, and the table will be inserted into the Word document where they are typing. The user can then input info into the table. Also, what I want to do is that after the user is done typing this document(lets say it's over 200 pages with 50+ tables) I want them to be able to press another button and the document will find all the tables, gather the information in the table and create a text(with .txt extension) with some of the info in all those tables...I know how to gather the information from a table(that is currently in Excel) and print out the text file...I just need help with all the stuff before that... Thanks in advance for your help!
Skilit
Ok well I figured out how to create a general table, but I want a certain format for some of the columns and insert predefined text in a particular row...any takers?
Excel: Copy Rows With Specific Word
Please forgive my newbie-ness if this is very easy, i dont have any experience doing something like this.
What i would like to do is have a macro that copies rows which contain a specific word such as 'sub-total' etc., from 1 worksheet to another.
So i run the macro, it runs through the sheet and copies only rows that have the specified word in that row.
or is there a better way to do this?
thanks in advance,
Niall
Excel Macro; Find Text, Enter Row #
I'm just starting out with VBA and my wife has a project she'd like to complete ASAP.
Any help is appreciated.
Using the Sire name/text in column E, find that name/text in column H, copy the corresponding Record # in column G and paste that into column B.
Then use Dam name in column F, find that name/text in column H, copy the corresponding Record # in column G and paste that into column C.
TIA, Dave
Insert Excel Range At Specific Location In Word
I have code that copies a range from each worksheet and pastes them into Word. Trouble is, I cannot figure out how to past them into specific locations in the word doc. Any suggestions? I have tried bookmarks to NO solution. The codes I am using looks like this:
(cant seem to add a zip file)
also would appreciate suggestions on how to work from a template, and how to put in a "save as"
Sub CopyWorksheetsToWord()
' requires a reference to the Word Object library:
' in the VBE select Tools, References and check the Microsoft Word X.X object library
Dim wdApp As Word.Application, wdDoc As Word.Document, ws As Worksheet
Application.ScreenUpdating = False
Application.StatusBar = "Creating new document..."
Set wdApp = New Word.Application
'Set wdDoc = wdApp.Documents.Add
Set wdDoc = wdApp.Documents.Open(Filename:="C:Documents and SettingsjroseDesktopKCA-Testing.doc")
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Copying data from " & ws.Name & "..."
ws.UsedRange.Copy ' or edit to the range you want to copy
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.InsertParagraphAfter
wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range.Paste
If wordDoc.Bookmarks.Exists("pts") = True Then
wordDoc.Bookmarks("pts").Range.PasteSpecial
Application.CutCopyMode = False
If Not ws.Name = Worksheets(Worksheets.Count).Name Then
With wdDoc.Paragraphs(wdDoc.Paragraphs.Count).Range
.InsertParagraphBefore
.Collapse Direction:=wdCollapseEnd
' .InsertBreak Type:=wdPageBreak
End With
End If
Next ws
Set ws = Nothing
Application.StatusBar = "Cleaning up..."
' apply normal view
With wdApp.ActiveWindow
If .View.SplitSpecial = wdPaneNone Then
.ActivePane.View.Type = wdPrintView
Else
.View.Type = wdPrintView
End If
End With
Set wdDoc = Nothing
wdApp.Visible = True
Set wdApp = Nothing
Application.StatusBar = False
End Sub
Word / Excel Macro
Can anyone help me? I have written a Word 2000 macro which opens up an Excel spreadsheet. This is also being used by Office 97 users. I put in the appropriate references but what I am finding is that although I can run it without a problem Office 97 users get a 'Cannot find project or library' error message.
When I check the References box it becomes clear that although all other references have automatically changed from version 9.0 to version 8.0 this does not happen with the Excel one (it just comes up saying MISSING) despite the user having Excel 8.0 in their list.
Is there something else I need to do to counteract this?
Word && Excel Macro
Dear All,
How do I write a Macro that will link tasks in Excel & Word? I want to copy a table from Excel and paste in a word document and then copy a different table and paste it in to a different Word document.
I do not think this can be simply 'recorded' using the VBA record macro function so how do I begin to write it?
Thank you for your time,
internationally
Excel To Word Via Macro
I would like to know if there is any way possible to export charts created in Excel through to a word document via a macro.
Word Macro To Excel (more...)
Hi,
I use Word macro to check if an Excel file is alreay opened.
If Not FileOpened(ActiveDocument.Path & "myFile.xls") Then
Set objExcel = Nothing
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.workbooks.Open(ActiveDocument.Path & "myFile.xls", 0, True)
Set objWorksheet = objWorkbook.sheets("Sheet1")
objExcel.Visible = True
End If
Function FileOpened(strFileName As String) As Boolean
On Error Resume Next
FileOpened = False
Open strFileName For Binary Access Read Write Lock Read Write As #1
Close #1
If Err.Number <> 0 Then
FileOpened = True
Err.Clear
End If
End Function
The problem are:
1. if myFile is not opened, the code will open it. However, if the code is run again and again, it fails to see the file is already opened so it creates a new Excel object and open the file again and again. What can I do?
2. if the file is already opened, how to set the Excel, workbook and worksheet objects to the file and worksheet (instead of creating new Excel application, workbook and worksheet)?
Please help.
Jeff
Insert A Macro From Vb6 Into Word Or Excel
hi there,
i would like to know if i can insert a piece of vba code ,which is in my vb6 app, into Word and Excel into a new marco or something and if that is possible, how i've got to do that.
Arno
Controlling Excel From A Word Macro
Hi guys, afraid I’m not a regular programmer, just a humble PC user with only elementary knowledge of VB/VBA who likes to write the occasional macro to automate repetitive/time consuming tasks. I’m now in need of an expert’s help to come up with a bit of VBA code that will control Excel from within Word. I have two questions.
First Question
Below is a macro I use to insert selected text from a Word document, into an Excel sheet in a named cell range. Is there a way I can incorporate these two lines of code in the macro
Range("B65536").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
so that the selected text is inserted into the first empty cell in column B instead of to a named cell?
Code:
Sub InsertSelectedTextIntoExcelsheet()
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
Dim ExcelWasNotRunning As Boolean
Dim WorkbookToWorkOn As String
On Error Resume Next
Set oXL = GetObject(, "Excel.Application")
If Err Then
ExcelWasNotRunning = True
Set oXL = New Excel.Application
End If
On Error GoTo Err_Handler
Set oWB = oXL.Workbooks.Open("C:Accounts.xls")
oXL.Worksheets("Ledger").Range("B7").Value = Selection.Text
Set oXL = Nothing
If ExcelWasNotRunning Then
oXL.Quit
End If
Set oRng = Nothing
Set oSheet = Nothing
Set oWB = Nothing
Set oXL = Nothing
Exit Sub
Err_Handler:
MsgBox WorkbookToWorkOn & " caused a problem. " & Err.Description, vbCritical, "Error: " _
& Err.Number
If ExcelWasNotRunning Then
oXL.Quit
End If
End Sub
Second Question
There are times when I would like text from three cells in a Bookmarked table in Word to be inserted into three empty cells on the "Ledger" sheet. For example:
Insert text from = (Table1 G2) into first empty cell in column C of "Ledger" sheet
Insert text from = (Table1 G3) into first empty cell in column D of "Ledger" sheet
Insert text from = (Table1 G4) into first empty cell in column E of "Ledger" sheet
Again, is there a bit of VBA code that will achieve this?
Your help is much appreciated.
Running Excel Macro From Word
i have 2 macros, one in word, which manipulates the document and saves the file as an excel file on my desktop, and another macro in excel which manipulates the data and saves it as a file with no extension.
i for the word macro to run the excel macro after it is finished. i have tried several things but it doesnt seem to work, (i do have the references set properly to accept excel commands)
can anyone help with the code to complete this??
any help would be greatly appreciated
Tip For (word&&excel) Macro Programing
I know some Vb and have done a lot in ASP but now Ii want to do it in
Office. I want to export data from word to execel and so on.
Does anyone have tip to start, a homepage or some newbie code so I can understand the basic moves in vb-office.
greateful for any help......
Formatting Word With An Excel MAcro
I am developing a report that dumps data to Word from Excel, but I have not been able to format the Word document with the Macro. I need to change the paper size and layout and insert a header. If someone can get me started down the path, that would be great. I have successfully gotten the body text and data fields to import, but not the formatting portion.
Thanks
Open MS Word Doc From Excel Macro
Hi all. Help is much appreciated again. I'm trying to open a MS Word doc from within Excel VBA code. I'm seeing all kinds of discussion about early binding, late binding, etc. Do I really need to go through all that or can I just make a simple call somehow to exec MS Word and open a file.
Thanks.
Word Wrap In Excel Macro
Have a large amount of data on which to do a find/replace
routine. Current macro works fine, unless cell contains
multiple entries using word wrap. How can I look for
these specific multiple entries and replace with a single
coded entry?
I'm trying to replace this:
Irritant (Eyes, skin, respiratory tract)
Coughing, Choking, Headaches, Dizziness, Drowsiness
with:
Irritant-eyes-inhale-contact
Here's a snippet of the code I'm using:
Selection.Replace What:="Irritant (Eyes, skin,
respiratory tract)" & Chr(10) & "Coughing, Choking,
Headaches, Dizziness, Drowsiness", Replacement:="Irritant-
eyes-inhale-contact", LookAt:=xlWhole,
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Irritant (respiratory system,
skin)" & Chr(10) & "Risk of serious damage to eyes",
Replacement:="Irritant-eyes-inhale-contact",
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, ReplaceFormat:=False
The first Selection.Replace works and the second doesn't.
Any suggestions?
Edit Word Doc In An Excel Macro
I am trying to do a global replace of all occurrences of the string "Comp" with the string "&&&" everywhere in the first table in a Word document using the following code executed from Excel:
Sub ScanOutlines()
EditWordTable_Method2 "C:Test ", "Test"
End Sub
Public Sub EditWordTable_Method2(sDocPath As String, wdDocName As String)
Dim WordDocument As Object
Dim wdApp As Object
Set wdApp = GetObject("", "Word.Application")
DoEvents
wdApp.Application.Documents.Open sDocPath & wdDocName & ".doc"
wdApp.Application.Visible = True
wdApp.ActiveDocument.Tables(1).Select
'Change "Comp" to "&&&" . . .
wdApp.Selection.Find.ClearFormatting
wdApp.Selection.Find.Replacement.ClearFormatting
With wdApp.Selection.Find
.Text = "Comp"
.Replacement.Text = "&&&"
.Forward = True
.Wrap = WdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
wdApp.Selection.Find.Execute Replace:=wdReplaceAll
DoEvents
wdApp.ActiveDocument.Tables(1).Range.Copy
Sheets.Add.Name = "Temp"
ActiveSheet.PasteSpecial Format:="HTML", Link:=False,
DisplayAsIcon:=False
The code successfully opens the Word file, and selects the table but does not perform the replace. Instead, the "Replace:=wdReplaceAll" execution only selects the first instance of "Comp" in the table but does not perform any actual replaces. The code after the replace runs fine also, i.e. the table gets copied and pasted into the Excel sheet "Temp" just fine. But for some reason, the code refuses to perform any edits to the Word table. Anyone know what's wrong here? Thanks!
In Excel, Calling Word Macro
Please Help, i have gotten this far and am stuck: I have an Excel Macro that copies a specific cell, and it then needs to call a Word macro to paste the contents. I know the copy/paste commands, but am having trouble calling the Word Macro. Any help would be appreciated, for i am tearing my hair out
Access Excel Using Word Macro
Hey guys, I'm new here and need some help.
I'm using VB in MS Word and I need to access data from Excel. Does anyone know how to open an Excel file and copy or assign data from a cell to a variable in MS Word?
Word Wrap In Excel Macro
Have a large amount of data on which to do a find/replace
routine. Current macro works fine, unless cell contains
multiple entries using word wrap. How can I look for
these specific multiple entries and replace with a single
coded entry?
I'm trying to replace this:
Irritant (Eyes, skin, respiratory tract)
Coughing, Choking, Headaches, Dizziness, Drowsiness
with:
Irritant-eyes-inhale-contact
Here's a snippet of the code I'm using:
Selection.Replace What:="Irritant (Eyes, skin,
respiratory tract)" & Chr(10) & "Coughing, Choking,
Headaches, Dizziness, Drowsiness", Replacement:="Irritant-
eyes-inhale-contact", LookAt:=xlWhole,
SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, ReplaceFormat:=False
Selection.Replace What:="Irritant (respiratory system,
skin)" & Chr(10) & "Risk of serious damage to eyes",
Replacement:="Irritant-eyes-inhale-contact",
LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False,
SearchFormat:=False, ReplaceFormat:=False
The first Selection.Replace works and the second doesn't.
Any suggestions?
Word Excel Templates VBA/Macro Help
I am doing programming on word and excel templates. But when i am running the templates main form is not executing. It is telling to enable macro. I tried it but not working. Please help me how to execute macro in word & excel. If yu suggest any good tutorial on VBA basic stuff that would be appreciated.
Edited by - programmercomputer on 3/5/2005 1:45:29 AM
Run Excel Macro From Word Pass Variable
As this is my first post i would just like to say this forum is wonderfull i have been able to find so much help on it. Usually i can find the answeres i seek with out posting just by searching a bit but this time it seems nothing came up or more likely i missed it.
what i'm trying to do is call a macro passing two arguments to excel from word and pass a result variable back from execel.
when excel opens it loads a macro. This all has to happen behind the sceens (why it is not visible).
word:
Sub cmdGetNumber()
Dim XL As Object
On Error GoTo OLE_ERROR
Set XL = CreateObject("Excel.Application")
'Open Excel document
XL.Workbooks.Open "C:Documents and SettingsSCummingsDesktopECR_NUMBERS.xls"
XL.Visible = False
XL.Workbooks(1).Activate
**************************
' call fuction here... something like:
ActiveDocument.FormFields("Text1").Result = cmdReturnNumber(strOriginator, strDate)
**************************
'XL.Workbooks(1).Save
XL.Application.Quit
Set XL = Nothing
'Unload Profile Form
Unload Me
OLE_ERROR:
MsgBox Error$(Err)
If Not (XL Is Nothing) Then
Set XL = Nothing
End If
Unload Me
End Sub
excel:
Function cmdReturnNumber(strName, strDate)
cmdNewNumber_Click
txtPerson.Text = strName
txtRequestDate.Text = strDate
txtRequestedBy.Text = strName
cmdReturnNumber = txtNumber.Text
cmdSubmit_Click
End Function
any help would be very much appriciated, and if you need me to clarifiy something let me know. i'm not sure if i explained myself well enough.
thank you,
shane
Open Word File Using An Excel Macro
Hi All,
What VB command do I use to open a Word document from an Excel document? Then, within the same Excel macro, how do I initiate a Macro within the word document I have just opened?
Help is much appreciated,
internationally
Need Macro To Launch Excel Template From Word
VBA neophyte here.
I need a macro to launch an Excel template from within Word. I have managed to glean the code below from off the web to launch the app but I do not know how get it to open a workbook.
Many thanks in advance,
Wbaker
Sub Excel()
Dim MyAppID
MyAppID = Shell("C:Program FilesMicrosoft OfficeOFFICE11excel.exe", vbMaximizedFocus)
AppActivate MyAppID
End Sub
Macro In Word To Import Excel Graph
Does anybody have any code that works within Microsoft Word to:
Create a button with a macro attached that imports an excel graph into Word without neccesarily having the Excel S/S within which the graph has been created open at the time.
And in the meantime can anyone tell me why the following code is not working?
I get a message "User defined type not defined"
Code:
Sub MonthlySalesFigures()
Dim y As Word.Application
Set y = CreateObject("Word.Application")
With y
.Visible = True
.Documents.Open Filename:="G:GillsWordExsGreatSouthernRealEstateTemplatesNormally.dotMonthlySalesReport.doc"
Worksheets("AreaAnnualSales").Range("A2:C29").Select
.Selection.GoTo What:=wdGoToBookmark, Name:="AreaMonthlySales"
.Selection.Paste
Application.CutCopyMode.False
Worksheets("SalesRepSales").Range("A2:C11").Select
.Selection.GoTo What:=wdGoToBookmark, Name:="SalesRepMonthlyCommRet"
.Selection.Paste
Application.CutCopyMode.False
End With
End Sub
Thanks heaps
|