Consulting

Results 1 to 9 of 9

Thread: Report Generation

  1. #1
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    3
    Location

    Report Generation

    Hi all,I quite new to VBA so I would like to know if it is possible to generate a report using Microsoft Excel. For example, I have a command button. A user clicks the command button and a report will be generated based on the information in Excel Sheets. For example, Sheet"Name".What types of reports are available? Or is there nothing to be done?I'm sorry if it's not clear, do clarify with me if there are any questionsMany thanks appreciated!! Thanks!

  2. #2
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Lots of questions. You will have to give more info per your request. Mabe post a workbook with sample data and a sample report.....

    click post reply....scroll down and look for mangage attachments.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  3. #3
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    3
    Location
    attached is an example of the excel file that has the information

  4. #4
    VBAX Newbie
    Joined
    Feb 2009
    Posts
    3
    Location
    Attached is a report that can be generated

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    This copies a range to a new word document.

    [VBA]Sub CopyTableToAnyWordDocument()

    Dim wdApp As Word.Application

    ThisWorkbook.Sheets("Table").Range("A1:B6").Copy
    Set wdApp = New Word.Application
    With wdApp
    .Documents.Add
    .Visible = True
    End With
    With wdApp.Selection
    .EndKey Unit:=wdStory
    .TypeParagraph
    .Paste
    End With

    Set wdApp = Nothing

    End Sub[/VBA]
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location
    Hi,
    How would I adapt the code below to work with Notepad (instead of Word), and instead of cutting/pasting data from a worksheet, I add strings created in VBA?
    Thanks

  7. #7
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Hi Ukdane,

    From Help:
    TextStream Object


    Description
    Facilitates sequential access to file.
    Syntax
    TextStream.{property | method}
    The property and method arguments can be any of the properties and methods associated with the TextStream object. Note that in actual usage TextStream is replaced by a variable placeholder representing the TextStream object returned from the FileSystemObject.
    Remarks
    In the following code, a is the TextStream object returned by the CreateTextFile method on the FileSystemObject:
    Set fs = CreateObject("Scripting.FileSystemObject")Set a = fs.CreateTextFile("c:\testfile.txt", True)a.WriteLine("This is a test.")a.CloseWriteLine and Close are two methods of the TextStream Object.

    You may wish to check out the TextStream and FileSystem Objects.

    Mark

  8. #8
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location
    Thanks GTO

  9. #9
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    You bet :-) I did re-read my post and wanted to ensure that my suggestion is not taken as simply "go read help", for I would not want to leave that impression. After you get a chance to try creating and writing a textfile, if anything goes kaBOOM!, I sure hope you post back :-)

    Mark
    Last edited by GTO; 08-13-2009 at 03:25 AM. Reason: Yikes! You wouldn't know my native tongue is American English...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •