Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Easy One - Calling Macro From Another


I'm writing a macro which goes through each shape, header and footer in a Word document individually and runs an external macro on it. This external macro was not written by me and I've no access to the code.

So I have the macro loop through all the objects in question and call the macro with Run, but the whole thing seems to stop running after the Run statement, and the macro appears to run on the whole document, excluding the headers and footers. Should I be using something else rather than Run?


VB Code:
Sub CleanWholeDocument() Dim sShape As ShapeDim fNote As FootnoteDim HeadFoot As HeaderFooterDim sSection As Section For Each sSection In ActiveDocument.Sections    For Each HeadFoot In sSection.Headers        HeadFoot.Range.Select        Application.Run MacroName:="tw4winClean.Main"    Next HeadFootNext sSection For Each fNote In ActiveDocument.Footnotes    fNote.Range.Select    Application.Run MacroName:="tw4winClean.Main"Next fNote For Each sShape In ActiveDocument.Shapes    If sShape.TextFrame.HasText Then        sShape.TextFrame.TextRange.Select        Application.Run MacroName:="tw4winClean.Main"    End IfNext sShape          Application.Run MacroName:="tw4winClean.Main" End Sub




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Calling A Macro
How can i call a macro as soon as a form is loaded from outlook?

Calling A Macro...
Hi all,

I need to call ADD-IN and use one of its functions to run on a workbook that is opened from VB6.
I have noticed that when VB opens an instance of Excel it does not open the ADD-IN's that would have opened with it if it was opened as a Normal App.

How can I call this ADD-IN without having to copy its code across to the app I am writing.

Any help advice would be great....

Thanks in advance


[Edited by Rocks on 01-04-2001 at 11:43 AM]

Calling A Macro From A Macro
Hi

I am writing a macro within Excel. I want this to invoke a word object:

Dim obj As Object
Set obj = CreateObject("Word.Application")
obj.Visible = True

And then maybe load my template file, and call a macro within that. Basically, I want to create a mail merge autoamtically from the data in the Excel file at the touch of a button.

Regards
Ben

Calling A MSAccess Macro
Is there a way that I can call a MSAcess macro in a closed database from VB 6.0? Thanks for any help.

Calling An Excel Macro From VB
I've posted my code in an attempt to get some help. The line - "xl.run OverallLoop" is an attempt to call a macro in an excel application. It doesn't seem to be working. Can anyone help? ps thanks to the guys who helped before!

Sub VBOverallLoop()
Dim ThisOpenPath As String, NRuns As Integer, Age As Integer
Dim VBThisFileName As String, NPats As Integer, PatAge As Integer
Dim i As Integer, j As Integer

NRuns = frmDiab.txtNRuns
NPats = frmDiab.txtNPats

ThisOpenPath = "c:PTDMMHDiab.xls"

Set xl = New Excel.Application
Application.Visible = False
Set xlWorkbook = xl.Workbooks.Open(ThisOpenPath)
Set xlWorksheet = xlWorkbook.Sheets("TherapyParams")
xlWorksheet.Activate
Set xlNumbTherapy = xlWorksheet.Range("NumbTherapy")


InitialTime = Timer
For i = 1 To NRuns
For j = 1 To 1 ' replace with xlNumbTherapy

frmDiab.lblProgress.Caption = "Run " & i & ", Therapy " & j & ""

Set xlWorkbook = xl.Workbooks.Open(ThisOpenPath)
Set xlWorksheet = xlWorkbook.Sheets("OtherParameters")
xlWorksheet.Activate
Set xlRangeDiabFlag = xlWorksheet.Range("RngDiabFlag")
Set xlRangeNPats = xlWorksheet.Range("RngVBNPats")

Set xlRangeFileName = xlWorksheet.Range("RngFileName")
Age = xlWorksheet.Range("RngAgeForVB").Value

xlRangeDiabFlag.Value = j
VBThisFileName = "Therapy" & j & "Run" & i & ""
xlRangeFileName.Value = VBThisFileName
xlRangeNPats = NPats

xl.Run OverallLoop
'Call DeleteSheets
temptxt = "c:PTDM" & VBThisFileName & ".xls"
xlWorkbook.SaveAs temptxt
Next j
Next i

xlWorkbook.Close
xl.Quit
Set xl = Nothing
Set xlWorksheet = Nothing
Set xlWorkbook = Nothing


If Timer - InitialTime < 300 Then
ThisTimeTaken1 = Int(Timer - InitialTime)
ThisTimeTaken2 = "seconds"
Else
ThisTimeTaken1 = Int((1 / 60) * Int(Timer - InitialTime))
ThisTimeTaken2 = "minutes"
End If
frmDiab.RunButton.Enabled = False
frmDiab.Show
frmDiab.lblProgress.Caption = "Done in " & ThisTimeTaken1 & " " & ThisTimeTaken2

frmDiab.FinishButton.Enabled = True

End Sub

Calling A Macro In A Different Project
Hi
I have a macro within Excel which opens all workbooks within a specified folder. For each of these workbooks I need to call a macro that exists within the workbook.
I'm having problems getting VBA to do the call using a variable as the workbook name (the module & macro names can be specified as a constant). In fact I'm even having problems doing the external call when I explicitly write out the workbook name in the call.
Thanks for your help.

Calling A Macro From Another File
Dear Friends,

How do i call a macro from another file? For example, I want to write a macro in "c:ook1.xls" which will call a macro(sub test()) present in "d:ook1.xls".

Requesting your kind help in this regard.

Regards,
S. Sivakumar

Easy - Calling A Function
I have created a module containing many Public functions.

When a button is pressed on a form i want a function (say Calc01) to be called, but how do i code that. What code do i need to call that function. I'm sure it is simple!!!

Please Help,
James

Calling External Excel 4 Macro
Is it possible to call an external excel 4 macro from VB? We have a very complicated macro that doesn't seem to have an equivalent in VBA, and I need to incorporate it into my VB program...anyone have any knowledge of this?

Thanks!

Calling Macro In Excel From Access With Vba
HI

Im new here, this is my first question and I hope someone out there can lend me hand or point me in the right direction. Thanks.

I have developed an Excel template with a macro in VBA. I have ten different templates which I want to fire off. At the moment, all ten is fired off from Access using a shell command, but Im finding that it uses too much virtual memory. The ten templates are all the same except using different parameters, so I am thinking of just having one template and using the Access to call up a template and passing in the parameter so the macro can act on it using that parameter. Is there a way of calling a macro function in Excel using vba?

Anyone got any advice, will be greatly appreciated.

Cheers

Calling Access Macro From Excel
I have a model, running from a macro in Excel. The model cycles through hundreds of thousands of iterations for forecasting purposes. I am taking the output from the model after each iteration and dumping it into Access.

I am experiencing two problems calling the Access macro (that imports the data and places it in the appropriate table) from Excel:

1.) The database connection times out. The speed of the Excel macro is drastically reduced if I open Access after each iteration to dump data in. Therefore I have connected to Access in the beginning of my Excel macro and am only calling the Access macro after each iteration. I tried to open and close the database with each iteration, but it is time consuming and sometimes the database doesn't close which causes the program to halt.

2.) I call the Access macro in the following manner:

In the beginning of the macro the following is established:
Dim cn As New Access.Application
cn.OpenCurrentDatabase ("C:
ame.mdb")
cn.Visible = False

Then after each iteration:
SendKeys "MacroName{ENTER}"
cn.RunCommand acCmdRunMacro

Then at the very end:
cn.CloseCurrentDatabase
cn.Quit acQuitSaveNone
Set cn = Nothing

The problem is with the "SENDKEYS" statement. Sometimes, about 1% of the time, the macro seems to skip over the line. The macro window will open in Access prompting me to enter the macro name and "ENTER".

Any wisdom that could be imparted regarding these two issues would be greatly appreciated! Thanks for your help.

Calling Access Macro Problem
Is there anyway to keep access from popping up while doing the snippit below?

'Open database
objaccess.OpenCurrentDatabase "my database"

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

Calling A Access 2000 Macro Within VB6
Does anyone know how to call and run a Access 2000 macro from within a VB6 application.

Any help appreciated,

Regards,

Moben.

Need Help With Calling Macro Automatically &lt;RESOLVED&gt;
I'm currently using vb in excel to do several tasks, although one troubles me. I would greatly appreciate some sort of insight in this matter. Im trying to print the spreadsheet at midnight. The printing is no problem, i just call on a macro to do that. The issue arises with how to call that macro at midnight. Ive tried several ways including an ondata command, but have found no way to check the time, to call the macro automatically from either the spreadsheet or a command. Any help would greatly be appreciated....





Edited by - flopro on 6/14/2004 2:18:07 PM

Calling Ecternal Macro In Excel Using VB
I have 2 files open-- abc.xls and xyz.xls.
How can I call a Sub (say Sub Test() in module1) from abc.xls to a macro in xyz.xls


Thanks.

~BS

Install Macro's Easy
Hello,

I'm programming macro's but the distribution of them is rather difficult. Each time I make an adjustment I have to let people copy the new version of the normal.dot over the old version...
What ways are there to automaticly install these modifications? Could I use an setup.exe or an other file which only has to be double clicked in order to let the new file be installed?

Easy Macro Question
How to reference a CheckBox on another worksheet.
If I have two worksheets, named Sheet1 and Sheet2 and a checkbox, (chk1) on sheet1, how do I check the value of chk1.value, while working on sheet2?

Calling A Macro By Doubling Clicking A Cell
Can i call a macro from a sheet by double clicking a cell?
thanks

Visual Basic Calling An Excel Macro?
Is it possible to have Visual Basic call a macro from excel?

Calling Microsoft Access Module Or Macro From VB
I would like to call a Microsoft Access Module or Macro from a VB executable. This way I could schedule some database activity from my NT server.

I do not know the commands to open an Access Database (with password protection) and us the DoCmd.

Please Help!!

Calling A Macro In Another Template In Word 2000
GOod day,

I am trying to call a macro in a template that I attach a run-time and the error I get keeps telling me that it is unable to run the specified macro...the code is as follows

Code:Sub ApplyNewTemplate()

' attach the new Signature template to override styles

    With ActiveDocument
        .UpdateStylesOnOpen = True
        .AttachedTemplate = _
            "C:WINNTProfiles" + Environ("USERNAME") + "Application DataMicrosoftTemplatesSignature.dot"
    End With

Quote:THE ERROR OCCURS HERE...Should I be using another method?
' auto-run the conversion to the new look after the signature template is attached
    Application.Run MacroName:="Signature.NewLook.NewLookSignature"
       

End Sub

Thanks in advance...



 
J.C.

"Do or do not, there is no try."

Performance In Embedded Macro And Calling From EXE Project
I wonder if embedded macro will perform much more faster than calling excel
object from standard .exe application?

Anyone with the answer why...please explain to me. Thanks!

Two More Easy Excel Macro Questions
i know this is pitiful, but I'm working without a helpfile...


1)Is there an easy way to see if the row is blank? What I'm doing below only checks the Active cell instead of the row.

2)If I am referencing the active cell, how do I activate the row so I can delete it?



If ActiveCell.Rows.Text = "" Then

Selection.Delete Shift:=xlUp
ConsEmptyRow = ConsEmptyRow + 1
else
'Do something else with it
end if

Thanks,
LauRa

Easy Excel Macro Question
I don't have the help file on my machine, and it's been awhile since I've done this. How do I set the range property?

For example

Dim MyRange as Range

MyRange = Activecell.range

This doesn't work because it wants more parameters for the range property.

I also tried Range(activecell), but that didn't work either.

Thanks,

LauRa

Calling A Regina REXX Program From Excel VB Macro
Does anyone know if it is possible to call a REGINA REXX program from an EXcel VB Macro.

Cheers

Simon

Easy Excel Macro Question: Shifting Cells
I can't remember the method to move to the next cell in a row or a column.

Calling An Excel Macro From An Access Database That Refers To That Database
hi

i have a macro in excel that inserts some values into a table in a database in access, but i want to make it so i dont have to touch the excel file, instead i have a module in the access file that calls the sub in the excel file, but then i get an error saying that the database is already open....is there a way of getting around this?

thanks

jimmyp

Why Wont This Work? EASY EASY EASY
Option Explicit
Dim numbers(10) As Integer
Dim counter As Integer

Private Sub Command1_Click()
counter = 1
While counter < 10
Preserve numbers(10)
lblDisplay = numbers(counter)
counter = counter + 1
Wend
End Sub

Needs to display #'s 1 to 10 using this method

EASY EASY EASY Quesation, Just Woundering!!!
What does this mean, I see it at the top of code windows and I just woundered what it is there for. Every one probably knows this but I don't cause it isn't mentioned I any books on VB.


Code:
Option Explicit

Word Macro Insert File/ Append Table Macro Issue.
Hello,

I was wondering if someone could help me with this problem...

When I use the following code to insert a table (from an external file), the table that is inserted does not append to the table in first document (which is what I want it to do)...

Sub Macro1()

Selection.Collapse Direction:=wdCollapseEnd
Selection.InsertFile FileName:="m:cat.DOC", Link:=True

End Sub

Would anyone know how I can make the contents of this file append to the table in the first document?

Thanks so much in advance,

Anne

Macro Opens A Document In Vba, Saves, Then Continue With Macro
Maybe the title isn't correct, but i've got the following problem.
I build a document that open a form. On this form there is a checkbox. When the checkbox is active and I press 'OK' a document has to be opened. On this document some changes can be made, then by pressing 'continue' this document is saved on 'c: emp' and closed. Then I want to go back to the first document and continue with it.
Is there some sort of halt or wait funtion to establish this?

The code I use is the following:

<code document1>
If chbFinPar = True Then
Documents.Open FileName:="f:Nieuwe format macroHuisstijlTestversiefinpar.doc"
Selection.EndKey , ActiveDocument.Bookmarks("bmkfinpar").Range
Selection.InsertFile FileName:="c: empfinpar.doc"
End If
<end code>

<code document2>
Private Sub cmdVrdr_Click()
ActiveDocument.SaveAs ("c: empfinpar.doc")
ActiveDocument.Close
End Sub
<end code>

Word Macro Editor Opens When I Misspell A Macro Name
I'm using Word 2000, and pressing Alt+F8 to access macros - just text strings - and here's the trouble:

I'm trying to make it possible for everyone here to use Word macros from the server. I've put a file out there called Macros.dot and it works great. Every machine in the building can see it and use it. Trouble is, if a user misspells a macro name the macro editor opens by default. It doesn't realize the user has misspelled something and thinks the user wants to write a new macro under the "new" name. User can click the X to close the editor, of course, but has now created a blank macro with a name very similar to a real macro. This will drive people (especially the less tech savvy) nuts, and clog up the file Macros.dot with garbage.

Is there a way to disable the macro editor from opening if an incorrect (nonexistent) macro name is typed? A check box somewhere, perhaps? I've tried but can't seem to find it, if it's there.

Thanks

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 To Hide Macro Option From Tools Macro, Macros
Hi,
Well, this is the situation. I created some macros (6) for a workbook. One this macros is adding a new Menu in the main Excel Menu. The idea is that the user does not need to go to options: Tools, Macros, Macro...and run the macro because I want them to do it from the menu specially created.
Also I prevented any user to edit the macros putting password if they want to see the codes.
Now How I can prevent a user to run all my macros from the option:
Tools, Macros, Macro...Can I hide a Macro from that menu?

Any way to remove this option in just this workbook not affecting the user if they want to work with a new one...?
Or may be a message saying that macro can be run from the menu if the user is trying too.
Any suggestion?
Thanks!
Gonza

Activate Command Button Excel - EASY, EASY
This is probably as basic as questions come. I have no problems with VB coding have done plenty of that and have tested my code but now, I want my code to be executed when a command button (embedded in the worksheet) is pressed. I have created a new command button from the ActiveX Control Toolbox and placed it on my spreadsheet, BUT, when I click on it, it selects the button, allows me to resize or move it but that's not what I want. I want it to execute the Command1_Click function.

Help greatly appreciated...

Calling C++ DLL - Invalid Calling Structure
First i got a could not find entry point in DLL error. i fixed that by specifying ordinal numbers in the VB app. now when i run the program i get an invalid calling structure error and then VB Studio crashes. I think the crash is do to the threading and debugging at the same time. i have heard about problems with that. how do i fix the invalid calling structure error.

HEADER ------------------
#ifdef DLL_EXPORTS
#undef EXPORTMODE
#define EXPORTMODE __declspec(dllexport)
#else
#undef EXPORTMODE
#define EXPORTMODE __declspec(dllimport)
#endif

EXPORTMODE bool StartThread(int nTime, int nInterval);
EXPORTMODE void StopThread();

SOURCE---------------------------
#include "stdafx.h"
#include "header.h"

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}

return TRUE;
}

EXPORTMODE bool StartThread(int nTime, int nInterval)
{
return true;
}

EXPORTMODE void StopThread()
{
}

Can You Get An Access Macro To Include Running An XL Macro
Is it possible to have an MS access run its own "thing" and in the middle of it all call on excel to run it owns macro?

Word 200 Vba Macro Help - Enable Track Changes In A Macro. Thanks
I was able to find a macro which takes an already mail merged document, and saves each each document as a separate file. The document's filename is taken from the already merged document. The script works. It's in red. See below.

The problem is I need to enable the track changes option.I recorded the following macro. It's in blue.
With ActiveDocument
.TrackRevisions = True
.PrintRevisions = True
.ShowRevisions = True
End With
End Sub

I tried to incorporate this code(blue) into the code (red) below. I added it between ActiveDocument.Sections.First.Range.Cut and Documents.Add but it didn't work.

ActiveDocument.Sections.First.Range.Cut
ActiveDocument.TrackRevisions = True
ActiveDocument.PrintRevisions = True
ActiveDocument.ShowRevisions = True
Documents.Add

It turned on track changes but it didn't create each new document. What am I doing wrong?


Desperately Seeking help!!

Script works perfectly.
Sub SplitMergeLetter()
' splitter Macro
' Macro created 16-08-98 by Doug Robbins to save each letter created by a
' mailmerge as a separate file.
'
Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
Selection.HomeKey Unit:=wdStory
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
sName = Selection
'set path below
sPath = "C:MERGELETTERS"
Docname = sPath & sName
ActiveDocument.Sections.First.Range.Cut

Documents.Add
With Selection
.Paste
.EndKey Unit:=wdStory
.MoveLeft Unit:=wdCharacter, Count:=1
.Delete Unit:=wdCharacter, Count:=1
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

Easy Upper Case Question..or Not So Easy?
This is probably easy. Using txtfirst.text, how do I convert each letter to uppercase AS IT IS TYPED.

I am trying to use:
old = txtFirst.SelStart
txtFirst.Text = UCase(txtFirst.Text)
txtFirst.SelStart = old

But if text is entered in lowercase, it types the text backwards in uppercase.

Help?!

Thanks!

Calling An Oracle Package.Procedure Works But Calling A Function In The Package Does Not ?
Hi,

I am trying to call a function in a package in Oracle, from VB. I am using the traditional ADODB with connection, command and parameter objects. The function has 6 input parameters and it returns a string value.

We have no problems reaching the similar Procedure under a package, but when it comes to accessing the function, it gives errors. I got "no descriptor found", after some changes "object stored Procedure does not exist" .

Any suggestions on how differently to access a function within a package as opposed to a procedure ?

Thanks,
Arch

Call Macro ~change Macro
I want to create a print preview from a access rapport

I'm using this code:

Code:
Private Sub Command1_Click()
Dim A As Object

Set A = CreateObject("Access.Application")
A.Visible = true
A.OpenCurrentDatabase (App.Path & "
ewP2.mdb")
A.docmd.RunMacro "macroprinten"
ENd SUb
the first macrocommand is openreport + report name
at this instruction there is a posibility to specify a WHERE instruction.

Is it posible to chance this where instruction in visual basic
?


Many thx
grz
EBS

Run Access Macro From Excel Macro
Hi

I am using Microsoft Office 2000 and trying to run an Access macro from an Excel macro, but my Excel macro does not seem to be working. When I run the Excel macro, nothing happens - I do not get an error and the code does not do what it is suppossed to. Below is my code:

Code:
Sub DisplayForm()
' Initialize string to database path.
Const strConPathToSamples = "C:Miscell est.mdb"

strDB = strConPathToSamples & "test.mdb"
' Create new instance of Microsoft Access.
Set appAccess = _
CreateObject("Access.Application")
' Open database in Microsoft Access window.
appAccess.OpenCurrentDatabase strConPathToSamples
' Run Access macro.
appAccess.DoCmd.RunMacro "Macro1", 1
End Sub
I have included the references to "Microsoft DAO 3.6 Object Library" and "Microsoft Access 9.0 Object Library."
Any help on this subject would be much appreciated.
Thanks

Modifying Macro Or Form With Macro
Is it possible to modify a userform or macro in a module with another macro?

I've got a database of clients that will probably have new clients from time to time. Currently using userforms to give check lists and of course that stuff is referenced in macros. Would be cool to write a macro that would allow a user to modify that stuff to add in choices as needed.

Can this be done?

Attatch A Macro To A Button With A Macro?
I am creating a new sheet using VBA, I would like to be able to add a button to this sheet (which I can do), and attach a macro to the button (which I cannot).

Can anyone tell me how to attatch a macro to a button using another macro? Or any other way of making the newly created button actually do anything?

Thanks!
-Shiv

Lotus Macro To Excel Macro Please Help!!
I know nothing about Lotus but I need to convert Lotus macro to Microsoft Excel. Can anyone help

Easy Answer To An Easy Question
I want to populate a combobox for a filelist. How can I do it?

Do Until Index = File1.ListCount

Combo1.AddItem File1.FileName
File1.listIndex = File1.listIndex + 1
Loop

Easy Maths Question (yes, Easy!)
I have two points, X1,Y1 and X2,Y2. I want to find the value from true north of X1,Y1 that X2,Y2 is.

How do I do it? I know you have to find the distance between the points, eg. X1 - X2, Y1 - Y2, but beyond that I have no idea. ;-)

If you don't know what I mean, then look here:

........o

....|
....o/

| is true north, / is the angle. o are the points. Ignore the .'s. =)

-Git

[Edited by git on 10-08-2000 at 05:10 AM]

Easy Easy Easy Question
This solution to this is very simple but I can't for the life of me remember it. I've been out of VB for a while.

I have the following SQL statement...


VB Code:
strWriteData = "INSERT INTO Clinic_Info(ID,Location_Num) " & _                     " VALUES (strUniqueID,strLocation)"


When I print this to the immediate window it's sending Oracle the names strUniqueID and strLocation. I don't want it to do this, I want it to (obviously) send in the VALUES of these variables. Not the variable names!

NOTE: That code might contain a syntax error because I just typed a quick example.

Copyright © 2005-08 www.BigResource.com, All rights reserved