How to open a worksheet from another workbook

 In this example I am opening the worksheet Sheet2 from workbook test2.xls.

Sub q()

'code written on 24/09/2008 by Pavandeep Puddupakkam
   FileNum = FreeFile ' next file number
    Open "C:\Hotfrog\test1.html" For Output As #FileNum ' creates the file if it doesn't exist
            Workbooks("test2.xls").Activate
            Sheets("Sheet2").Activate

            If Cells(1, 1) <> "" Then
            Title = Cells(2, 2)
            URL = Cells(1, 2)
           Print #FileNum, Cells(1, 2)
            Print #FileNum, "<title>"; Title; "</title>"
            Print #FileNum, "</head>"
           Else
            Print #FileNum, "<body>"
            Print #FileNum, "<table cellpadding="; """1"""; " cellspacing="; """1"""; " border="; """1"""; ">"
            Print #FileNum, "<thead>"
            Print #FileNum, "<tr><td rowspan="; """1"""; " colspan="; """3"""; ">"; Title; "</td></tr>"
            Print #FileNum, "</thead><tbody>"
           End If
     Close #FileNum ' close the file
    
End Sub

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Posted by: wiki
Posted on: 1/22/2010 at 10:21 AM
Tags: ,
Categories: VBA Macros
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (1) | Post RSSRSS comment feed

Comments

Add comment


 

  Country flag

biuquote
  • Comment
  • Preview
Loading