Results 1 to 6 of 6

Thread: Helpppp me with coddeeeeeee

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    2

    Helpppp me with coddeeeeeee

    Code:
    Imports System
    Imports Microsoft.VisualBasic
    
    Partial Public Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Sub GetDataFromWordDoc()
            Dim sPath As String
            Dim sFile As String
            Dim MyWd As Object
            sPath = "C:\ENGDATA\PDMS_Upload\Data_loading\BLOCK22\"
            sFile = Dir(sPath & "*.doc")
            Do While sFile <> ""
                MyWd = GetObject(sPath & sFile)
                MyWd.ActiveWindow.Selection.WholeStory()
                MyWd.ActiveWindow.Selection.Copy()
                Sheets("Sheet1").Cells.SpecialCells(xlCellTypeLastCell)
                Offset(1, 1).End(xlToLeft).PasteSpecial(xlPasteValues)
                sFile = Dir()
            Loop
            MyWd = Nothing
        End Sub
    End Class
    this is the code to convert word documents to excel.
    but i am getting error at underlines portion..the error is name not declared what should i do..I got thios code frm net and i just pasted it in visual studio..is there anybody to guide me to get my result??I am running short of tymm
    Last edited by Hack; Feb 10th, 2012 at 06:53 AM. Reason: Added Highlight Tags

  2. #2
    Lively Member
    Join Date
    Jul 2010
    Posts
    66

    Re: Helpppp me with coddeeeeeee

    You need to add MS-Excel file references in you code.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    2

    Re: Helpppp me with coddeeeeeee

    I have added Microsoft.office.Interop.excel as reference..is there anything else than this??

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Helpppp me with coddeeeeeee

    Moved From The Codebank (which is for sharing code rather than posting questions )

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Helpppp me with coddeeeeeee

    The only thing that comes to mind is to either Import the namespace... or use the fully qualified names ... here's the problem, the items marked in errors are constants or enums... they need to be defined before you can use them. they are defined in the Excel object model. I'm guessing by the look of the code, that it was actually designed to be run from an Excel macro within Excel... in which case all of those items would have been defined and in scope. You don't appear to be using them in Excel, so you need to get them defined (by adding the reference) and bring them in scope (by importing the namespace).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Addicted Member vb_ftw's Avatar
    Join Date
    Dec 2010
    Posts
    139

    Re: Helpppp me with coddeeeeeee

    like techgnome said import the namespace

    vb Code:
    1. Imports Excel = Microsoft.Office.Interop.Excel

    and also activate the worksheet before pasting.

    vb Code:
    1. Dim xlWorkBook As Excel.Workbook
    2.                 Dim xlWorkSheet As Excel.Worksheet
    3. .
    4. .
    5. .
    6. xlWorkSheet = xlWorkBook.Sheets("Sheet1")
    7. xlWorkSheet.Activate()

Posting Permissions

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



Click Here to Expand Forum to Full Width