WORD MACRO PROBLEM

So I have a Macro that looks like this:
Sub LabelCamp4X4()
Set labelCamp = CreateObject("Word.Application") labelCamp.Visible = True
labelCamp.Documents.Add Template:="C:/templates/4x4Label.dotx"
End Sub
It all works fine the new document gets generated and it opens up based on my template file. But the problem now is that it opens on the back of the window so users feel that it has not been open and they end up clicking the button several times. So my question
is how do I get them to load as an active window?

Hi Rafaelhc,
If you have only one document opened, you can try to  minimize the active document.
Use the VBA code below:
Set labelCamp = CreateObject("Word.Application") labelCamp.Visible = True
labelCamp.Documents.Add Template:="C:/templates/4x4Label.dotx"
ActiveWindow.WindowState = wdWindowStateMinimize
Wind Zhang
TechNet Community Support

Similar Messages

  • Word VBA Macro problem with adding rows to table for BAPI call

    Hello all,
    I have code in Word macro which is reading file from the disk and converting it to binary. This binary should be inserted in the internal table (Dim As object) for further posting. Code is modified from the note 945682.
    Here is the code:
    Sub Read_File(FileNameFull As String)
    Dim oBinaryDataTab As Object
    Dim oBinaryDataRow As Object
    Dim lBytesToRead As Long
    Dim iNumChars, i As Integer
    Dim s1022, s2044, sX As String
    Dim fs, f, ts As Object
    Dim ReadFile As String
    ' Actually does the work of uploading the document in 1022 byte pieces.
    ReadFile = 0
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(FileNameFull)
    Set ts = f.OpenAsTextStream(1, -2)
    lBytesToRead = f.Size
    ReadFile = f.Size
    Do While ts.AtEndOfStream <> True
    If lBytesToRead < 1022 Then
    iNumChars = lBytesToRead
    Else
    iNumChars = 1022
    End If
    s1022 = ts.Read(iNumChars)
    s2044 = ""
    For i = 1 To Len(s1022)
    sX = Hex$(CByte(Asc(Mid(s1022, i, 1))))
    If Len(sX) = 1 Then
    sX = "0" + sX
    End If
    s2044 = s2044 + sX
    Next i
    Set oBinaryDataRow = oBinaryDataTab.Rows.Add
    oBinaryDataRow("LINE") = s2044
    lBytesToRead = lBytesToRead - iNumChars
    Loop
    End Sub
    But on the row "Set oBinaryDataRow = oBinaryDataTab.Rows.Add" code just stopped to work.
    Can somebody give me a hint how to proceed?
    I also tried to Dim oBinaryDataTable As Table and oBinaryDataRow as Row with the same result.
    oBinaryDataTable will be used as to post file to SAP system without GUI FTP connection. Because of that it must be converted to binary form.
    TIA
    Gordan
    P.S. Message to Moderator: Please, be so kind, and put the message in the proper forum if this is not this one.

    Self Resloved

  • Working with Word Templates and signed Word macros storing documents in SAP

    HI,
    we are storing word documents in the SAP BDS. The documents contain macros. The security settings for word macros cannot be reduced in our environment.
    So the documents / macros were signed. They work well. but as soon as they have been stored in the SAP BDS, we get the error message "You have modified a signed project.You do not have the correct key to sign this project. The signature will be discarded"
    After that the word macros do not run.
    Does anybody know this problem and the solution?
    Regards
    Harald

    And this is related to workflow in what way?
    Regards,
    Martin

  • Submit LabView Cluster to Word macro

    Hello,
    I want to run a word macro (Test100) from LabView and therefor its neccesary to submit the following argument (NewTable) to word:
    Type BookType
        KeyIn As String
        ValueIn As String
    End Type
    Type PSEXTable
        TKey As String
        TValue(0 To 100, 0 to 100) As String
        TColumnWidth (0 to 100) As Single
    End Type
    Private NewTable(0 To 50) As PSEXTable
    Sub Test100(NewTable)
    'Execute Macro with NewTable-Cluster
    End Sub
    I have tried to combine the values in LabView to a cluster-array,
    changed the single items or the complete cluster to variant, but Word
    was not able to read the values
    Has anybody an idea how it will work?
    Thanks an best regards, Helmut

    Thanks for your answer,
    but unfortunately I had to solve the problem in word.
    I have written a very big business-application in LabView (dont ask me
    why..) which controlls the complete workflow of a (also very big)
    company.
    I have included a tool which allows to write Word-Documents with
    special keywords, and LabView (together with Word) is able to replace
    or refreshe this keys with the values (or complete tables with
    pictures) of some different databases.
    Currently I have solved it with more-dimensional arrays, but it`s not perfect because of the memory usage.
    Has anybody else an idea what to do?
    Best regards, Helmut

  • Launch Microsoft Word macro with an applet

    Hi,
    I've got the following problem :
    First, I'd like to generate a .txt file (from an applet) on the client PC with informations (name, address...)
    Second, I'd like to lauch word macro from the applet and to merge informations from the .txt file with the .doc.
    Is it possible to do that ?
    Is it the best solution ? (the goal of the application is to generate letter to send to client)
    Thank You
    Sophie

    You can do it via Applet Servlet Communication.

  • MS-Word Macros with paramers via OLE

    Hi,
    This is probably more of an MS-Word question than a Forte question,
    but somebody out there might have done this before...
    I have some MS Word macros (Originally WordBasic, but recently they
    underwent automatic conversion to become Visual Basic) which take
    parameters.
    I used to call these macros from Forte using DDE.
    These days, it's a lot more fashionable to use OLE automation than
    DDE so I thought I'd give that a go.
    But I can't.
    Word.Applicaiton has a Run() method to run macros, but not macros
    with parameters. Is there a neat way of getting macro parameters
    across to Word?
    - Ed.
    Eduard E Havelaar | For the foolishness of God is wiser
    Information Services Section | than man's wisdom, and the weakness
    University of Canterbury | of God stronger than man's strength
    Christchurch, New Zealand | - I Cor 1:25

    have a look at this here article:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Word macro from Forms

    How can I start a macro in Word from Forms with the DDE-package? For Excel I use this command ('update' is the macro-name):
    DDE.Execute(ConvID, [run "'test.xls!update"]', 10000);
    Does anybody know the right approach for a Word macro?
    Thanks.
    null

    You should use OLE2 instead of DDE.
    Use this procedure if you're using Word version >= 97:
    PROCEDURE RUN_MACRO(cMacroName VARCHAR2) IS
    objWordApp OLE2.OBJ_TYPE := OLE2.CREATE_OBJ('WORD.APPLICATION');
    objArgList OLE2.LIST_TYPE := OLE2.CREATE_ARGLIST;
    BEGIN
    OLE2.ADD_ARG(objArgList,cMacroName);
    OLE2.INVOKE(objWordApp,'Run',objArgList);
    OLE2.DESTROY_ARGLIST(objArgList);
    OLE2.INVOKE(objWordApp,'QUIT');
    OLE2.RELEASE_OBJ(objWordApp);
    END;
    you can contact me for further explanation.
    Carlos

  • Export to Excel - Macro problems

    I have moved this to the Discoverer forum. Exporting to Excel - Macro Problems
    Message was edited by:
    user385142

    Hello Denes.
    Excuse me for send you a message in this way , but I dont find other way to contact with you.
    Im using the export_excel_pkg, and really it work good.
    I have only one problem, I tell you.
    When, in one item, data is very long and numeric, by example a EAN code, without any class of format, by default it give me the value ###, Im studing the package and trying to resolve this, but if you can send me any idea it can help me a lot.
    Thanks in advanced.
    You are doing a great work for us.

  • Making and running excel or word macros

    i would like to make a excel or word macro and run it in labview, but
    i don´t want to run without view the code directly in labview because
    i will need to modify the code in order to do differents things
    depending of the choose that i can make when the program it´s running
    so the answer is: how can i see the macro code in labview in and excel
    or word application and how to run it?
    don´t answer the solution it´s easymacro.com, couse i am a student and
    i need to see the diagram in order to learn
    thanks!

    I think ActiveX is what you need, but you'll have to elaborate a bit to modify and run macros. Look at the examples shipped with LabVIEW about controlling Excel, and see how those work. After that, you'll see that almost anything can be done using ActiveX.
    Good luck

  • Call Word Macro by using OLE2

    Hi,
    I use oracle forms 6i to call a word macro by using OLE2 .
    The macro called 'MyMacro' cannot be run and view although
    I can run it calling from MS Word seperatly.
    Code Below and No Errors running;
    DECLARE
    -- Declare the OLE objects
    MyApplication OLE2.OBJ_TYPE;
    MyDocuments OLE2.OBJ_TYPE;
    MyDocument OLE2.OBJ_TYPE;
    -- Declare handle to the OLE argument list
    args OLE2.LIST_TYPE;
    BEGIN
    -- Create the Word.Application object and make Word visible
    -- by setting the 'Visible' property to true
    MyApplication:=OLE2.CREATE_OBJ('Word.Application');
    OLE2.SET_PROPERTY(MyApplication, 'Visible', 1);
    -- get a handle on Documents collection
    MyDocuments:=OLE2.GET_OBJ_PROPERTY(MyApplication, 'Documents');
    -- Open a document doc.doc in C:\
    args:=OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args, 'C:\RAPOR\example.DOC');
    Mydocument :=OLE2.INVOKE_OBJ(MyDocuments,'Open',args);
    OLE2.DESTROY_ARGLIST(args);
    -- Execute the macro called 'MyMacro'
    args:=OLE2.CREATE_ARGLIST;
    OLE2.ADD_ARG(args, 'MyMacro');
    OLE2.INVOKE(MyApplication,'Run',args);
    OLE2.DESTROY_ARGLIST(args);
    OLE2.RELEASE_OBJ(MyDocument);
    OLE2.RELEASE_OBJ(MyDocuments);
    OLE2.RELEASE_OBJ(MyApplication);
    END;
    ------- code ends here-----
    Thanks.

    Hello. Try :
    myapplication := ole2.create_obj ('Word.Application');
    ole2.set_property (myapplication, 'Visible', 1);
    mydocuments := ole2.get_obj_property (myapplication, 'Documents');
    args := ole2.create_arglist;
    ole2.add_arg (args, :aux.nome_arquivo);
    mydocument := ole2.invoke_obj (mydocuments, 'Open', args);
    ole2.destroy_arglist (args);
    args := ole2.create_arglist;
    ole2.add_arg (args, 'maximize'); -- your macro
    ole2.invoke (myapplication, 'Run', args);
    ole2.destroy_arglist (args);
    args := ole2.create_arglist;
    ole2.add_arg (args, 'organize'); -- your macro
    ole2.invoke (myapplication, 'Run', args);
    ole2.destroy_arglist (args);
    args := ole2.create_arglist;
    ole2.add_arg (args, 'print'); -- your macro
    ole2.invoke (myapplication, 'Run', args);
    ole2.destroy_arglist (args);
    args := ole2.create_arglist;
    ole2.add_arg (args, 'Fechar');
    ole2.invoke (myapplication, 'Run', args);
    ole2.destroy_arglist (args);
    args := ole2.create_arglist;
    ole2.Release_obj (mydocument);
    ole2.Release_obj (mydocuments);
    ole2.Release_obj (myapplication); -- if dont need close application then coment this line

  • Word macros are disabled after converting to a PDF document.

    We work with Word templates that contain macros.
    After you convert a Word document into a PDF document, the macros of the attached template are disabled.
    The conversion takes place via the Adobe Acrobat icons.
    Used Products:
    - Windows7
    - With Office 2007 SP2
    - Adobe Acrobat 9.3.3 Pro
    The described problem only occurs in Word.  Outlook, Excel and Power Point are not affected.
    Thank you for your time and help

    Hi Buster,
    The error message you were receiving occurs when you try to convert a dynamic PDF file created with Adobe LiveCycle Designer.  This file is usually already a fillable form.  Unfortunately there is no workaround available for converting documents like this within the ExportPDF service.
    I'm sorry for the inconvenience.
    Please let me know if you have any questions or if I can be of further assistance.
    -David

  • Word Macros InDesign

    I followed all of the steps for using Word to write my scripts for InDesign.  It is a simple macro to go to the start of the line and delete 5 characters.
    Sub DeleteFive()
    ' DeleteFive Macro
        Selection.HomeKey Unit:=wdLine
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.Delete Unit:=wdCharacter, Count:=1
        Selection.Delete Unit:=wdCharacter, Count:=1
    End Sub
    It crashes when it tries to run the HomeKey line.
    Copied it to the folder in InDesign and added the .vbs file extension.
    I have a huge ID file I need to reformat and scripts would be a life and finger saver!
    Thanks!
    Rick
    InDesign CC
    Windows 7
    32 GB Ram

    Been banging this around a bit and think I found a decent solution.
    The scenario is that we have Word files that have the same style name as our InDesign file, but we were getting overrides coming in from Word even though the styles in the two programs were nearly identical. We are currently still in CS3 with this particular series but CS5 had similar issues. I think at least part of the problem are the so called "default" tabs in the Word doc.
    In InDesign, instead of telling the Word import filter to use the InDesign styles we told it to automatically rename. This puts "_wrd_#" at the end of the incoming style name where the "#" increments as a number. If you then delete those incoming styles and equate them to the corresponding InDesign style it works fantabulously. It keeps the overrides that were done in Word without any extra overrides on the other paragraphs.
    Hoping this might help someone else.
    All the Best,
    Ken

  • To Run a Word Macro recorded in 2000 in latest versions of Word

    Hello All,
    I have recorded a macro in word 2000 and calling that macro through Jacob 1.11 in my Java Swing application. That works fine for word 2000. I just want to use that same macro in Word Xp and for latest versions of Word. The problem is it is not invoking the macro in Word XP. But internally it is functionaning. I want to open it whenever the Word is opened.
    I have placed the macro other than in Normal.dot file and trying to open it. It opens in word 2000 as i said but not in XP and latest versions. Please refer the following code and help me....
    thanks in advance
    import java.io.File;
    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.Dispatch;
    import com.jacob.com.Variant;
    public class WordEventTest
         public WordEventTest()
                   try
                        File wordFileName = new File("C:"+File.separator+"example5.rtf");
                   String strWordFile = wordFileName.toString();
                        String secondFile = "C:" + File.separator+"example1.rtf";
                        ActiveXComponent wordDocuments = new ActiveXComponent("Word.Application");
                        wordDocuments.setProperty("Visible", new Variant(true));
                        Dispatch documents = Dispatch.get(wordDocuments, "Documents").toDispatch();
                        Dispatch openDocuments = Dispatch.call(documents, "Open", new Variant(strWordFile)).toDispatch();
                        Dispatch.call(openDocuments, "SaveAs", new Variant(secondFile), new Variant(6));
                        wordDocuments.setProperty("Visible", new Variant(false));
                        Dispatch copiedDocument = Dispatch.call(documents, "Open", new Variant(secondFile)).toDispatch();
                        Dispatch.call(wordDocuments, "Run", new Variant("iMedXGrading.NewMacros.Grading"));
                        Dispatch oldDocuments = Dispatch.call(documents, "Open", new Variant(secondFile)).toDispatch();
                   }catch(Exception e)
                        e.printStackTrace();
         public static void main(String args[])
              WordEventTest wordTest = new WordEventTest();
    }

    Hi All,
    While doing the same I am facing an issue.
    Actually I am getting the exception
    com.jacob.com.ComFailException: A COM exception has been encountered:
    At Invoke of: Documents
    Description: An unknown COM error has occured.
         at com.jacob.com.Dispatch.invokev(Native Method)
         at com.jacob.com.Dispatch.get(Dispatch.java)
         at WordEventTest.<init>(WordEventTest.java:24)
         at WordEventTest.main(WordEventTest.java:47)
    where line 24 marked as"Dispatch documents = Dispatch.get(wordDocuments, "Documents").toDispatch();"
    and the line 47 is as"WordEventTest wordTest = new WordEventTest();"
    any suggestion to remove the exception.
    Thanks
    Kushagra

  • Running word macro's in a Terminal Server session.

    I have multiple word documents that employees use. Within this document is a macro that is used to ask questions and then replace sections within the document with information entered with the macro.
    Problem is that when used in a Terminal Session (Server 2008 R2) it only updates the first page and a small section of the second page.
    When the document is used on a PC (Win 7) it runs fine and all the information supplied to the macro, is entered where it should be all the way through the document.
    I've searched the net high and low yet I cannot find any information relating to this.
    Any help would be great.
    Dean.

    So no Microsoft professional knows what's going on?

  • How to update a single field in Word macro

    Hello,
    I am trying to create an AutoOpen() macro that will update the file name and path when user opens in a Word document, but I can't seem to find anything explaining how to update a single field, specifically the {FILENAME \p} field.  There
    are other fields in the document, so I do not want to update all the fields.  Most of the links I found only explain how to update ALL fields. Can somebody please tell me how I can update only the filename and path field using an autoopen macro?
    Thank you

    Stefan's response is correct.
    Here is a macro that should update only filename fields.
    Sub FileNameFieldUpdateAllStory()
    ' Written by Charles Kyle Kenyon 15 November 2001 - modified for filename 10 Sept 2014
    ' repaired by Jezebel
    ' All Story Field Updater - Filename fields
    Dim oField As Field
    Dim oStory As Range
    ' On Error Resume Next
    For Each oStory In ActiveDocument.StoryRanges
    ' This goes into headers and footers as well as the regular document
    Do
    For Each oField In oStory.Fields
    If oField.Type = wdFieldFileName Then
    oField.Update
    End If
    Next oField
    Set oStory = oStory.NextStoryRange
    Loop Until oStory Is Nothing
    Next oStory
    End Sub
    See Installing Macros for help in using this.
    Charles Kenyon Madison, WI

Maybe you are looking for