PDA

View Full Version : Hidden Embedded Objects



burtburt
05-29-2008, 11:34 AM
Is it possible to embed a hidden object? I'm thinking that perhaps using hidden text you could also insert a hidden object. I'm trying to embedded a txt file in my word doc.

I don't want the user to see it but I do want to build a subroutine to open the text file(s) when they are needed. So the embedded txt file would need to be "found" then opened. The txt file will be created in a subrouting, embedded in the doc. Then later when the user requests for the information, the txt file can be activated/opened for viewing/saving.

fumei
05-29-2008, 11:38 AM
"Then later when the user requests for the information, the txt file can be activated/opened for viewing/saving."

Why not just have that by the user clicking an icon on the toolbar, or a menu item, or a shortcut key?

burtburt
05-29-2008, 02:25 PM
"Then later when the user requests for the information, the txt file can be activated/opened for viewing/saving."

Why not just have that by the user clicking an icon on the toolbar, or a menu item, or a shortcut key?

That's exactly what I planned to do. But my issue is understanding embedded files. How to store, hide and retrieve them.

burtburt
05-29-2008, 02:37 PM
So, I just verified that by selecting the icon of the embedded file and changing the font to "hidden" it is hidden.

Selection.InlineShapes.AddOLEObject ClassType:="WordPad.Document.1", _
FileName:="", LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\Program Files\Windows NT\Accessories\WORDPAD.EXE", IconIndex:=1, _
IconLabel:="WordPad Document"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
With Selection.Font
.Hidden = True
End With

Now I have to figure out how to enter data into the txt file. then retrieve it properly.

It's funny, when you insert an object the application opens, you make changes and close the application. All from within word and you never have to save the embedded file by itself. But when this process is recorded, none of the entries into the embedded txt get recorded.

burtburt
05-29-2008, 03:41 PM
A little closer now


Sub AddMyObject()

Selection.InlineShapes.AddOLEObject ClassType:="WordPad.Document.1", _
FileName:="", LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\Program Files\Windows NT\Accessories\WORDPAD.EXE", IconIndex:=1, _
IconLabel:="Add name here"
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Font.Hidden = True

End Sub
Sub RetrieveTest()

Dim i As Integer, j As Integer

j = ActiveDocument.InlineShapes.Count
For i = 1 To j
If ActiveDocument.InlineShapes(i).OLEFormat.IconLabel = "The one I want" Then
ActiveDocument.InlineShapes(i).OLEFormat.DoVerb wdOLEVerbOpen
End If
Next i

End Sub

fumei
05-30-2008, 11:01 AM
This seems overly complicated. But then I am unclear as to your purpose.

BTW: how is someone going to Select a hidden object? Do you always have Show/Hide on? What if it is off?

What is the point of selecting something hidden? If it is easy to select...then why bother having it hidden?

lucas
05-30-2008, 01:12 PM
Maybe the followhyperlink method.....change the path..

From Josephs KB entry (http://vbaexpress.com/kb/getarticle.php?kb_id=905) developed for Excel but adapted here to work in Word. See the attachment.....don't forget to change the path in the code and put the text file there....
Sub OpenFile()
Dim strTXTfile As String
Dim strFolder As String
strFolder = "F:\Temp\"
strTXTfile = strFolder & "test.txt"
ActiveDocument.FollowHyperlink Address:=strTXTfile, NewWindow:=True
End Sub

Look next to help on the main menu for a menu item called open text file in the attachment.

burtburt
06-09-2008, 09:43 AM
Ok. So let me explain what I'm trying to do a bit more. I have a document with a table of data. The table has 6 columns: Start Address, Data Lenght, Descrition, Hex Data, Data Type, Human Readible Data.

As you can probably see by the column names, this is a table of memorly locations. I'm passing this data from word to a SQL Database. Another team picks up the data from the data base and uses it to program the memory.

Well one of the teams meant to use the data, can't get to the SQL database. The want a txt file with just the start Address, Data Length and Hex data. So, rather than trying to figure out how to parse through my table and just pull the cells needed, What I did was to query the SQL database after I write out the full table. I do a selext sql statement to just pull the columns I need need. Sort them in order of "Start Address" and then I store that select query result in a txt file. I then take the txt file, and embedd it in the doc. It's hidden to all users but when a menu item is selected by this one group, the text file revieals itself from the hidden txt.

I'm just about done with this but I've run into a couple of snags.

1. The embedded file will open with the data but I can't seem to find a way to save it as a seperate file again to the local machine.
2. It works on other's systems but on mine, I must have set some strange state because now the txt opens in wordpad as a blank doc. But on other users machines it shows up just fine. I think I screwed something up when I was trying VBA ways to save the embedded file locally.


Sub HexDump(strProdID As String, strRefD As String)
Dim UserProfile As String
Dim sSQL As String
Dim i As Integer, j As Integer

Application.ScreenUpdating = False

UserProfile = Environ("USERPROFILE")

fName = UserProfile & "\Application Data\Cisco"
check_for_folder fName
fName = UserProfile & "\Application Data\Cisco\PCAMAP"
check_for_folder fName
fName = UserProfile & "\Application Data\Cisco\PCAMAP\Hex4" & strRefD & ".txt"
On Error Resume Next
Kill fName
On Error GoTo 0

Open fName For Random As 1
'If the txt file doesn't exist it is created
Close 1
Open fName For Append As 1

'**********************************
'Get Hex Dump from Database
sSQL = "Select StartAdd, DataLength, HexData from IDPROMData where Product_ID = " & _
strProdID & " Order By StartAdd ASC"

'MsgBox sSQL

Set oRS = con.Execute(sSQL)

On Error Resume Next
oRS.MoveFirst
On Error GoTo 0

If oRS.EOF Then
' MsgBox "Failed to write"
Else
While Not oRS.EOF
'put the lime in the coconut... Put the Database Record in the Text File
Print #1, Trim(oRS(0)) & vbTab & Trim(oRS(1)) & vbTab & Trim(oRS(2))
oRS.MoveNext
Wend
End If

Close 1

'*********************************
'Embeddes Hex Dump

For i = 1 To ActiveDocument.InlineShapes.Count

If ActiveDocument.InlineShapes(i).Type = wdInlineShapeEmbeddedOLEObject Then
If ActiveDocument.InlineShapes(i).OLEFormat.IconLabel = "Hex4" & strRefD Then
ActiveDocument.InlineShapes(i).Select
Selection.Font.Hidden = False
ActiveDocument.InlineShapes(i).Delete
Exit For
End If
End If
Next i

ActiveDocument.Bookmarks("Sect4_Rework").Select
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.InlineShapes.AddOLEObject FileName:=fName, _
LinkToFile:=False, DisplayAsIcon:=True, IconFileName:= _
"C:\WINDOWS\system32\notepad.exe", IconIndex:=0, IconLabel:="Hex4" & strRefD

For i = 1 To ActiveDocument.InlineShapes.Count
If ActiveDocument.InlineShapes(i).Type = wdInlineShapeEmbeddedOLEObject Then
If ActiveDocument.InlineShapes(i).OLEFormat.IconLabel = "Hex4" & strRefD Then
ActiveDocument.InlineShapes(i).Select
Selection.Font.Hidden = True
Exit For
End If
End If
Next i

Kill fName

ActiveDocument.Bookmarks("Sect3_IDPROM").Select
Application.ScreenUpdating = True

End Sub

Sub RetrieveHexText()

Dim myPCAMAP As Document
Dim i As Integer

Application.DisplayAlerts = wdAlertsNone

Set myPCAMAP = ActiveDocument
For i = 1 To myPCAMAP.InlineShapes.Count
If myPCAMAP.InlineShapes(i).Type = wdInlineShapeEmbeddedOLEObject Then
If Left(myPCAMAP.InlineShapes(i).OLEFormat.IconLabel, 4) = "Hex4" Then
' myPCAMAP.InlineShapes(i).OLEFormat.DoVerb wdOLEVerbOpen
'"WordPad.Document.1"
' With myPCAMAP.InlineShapes(i).OLEFormat
'' .ActivateAs ClassType:="Word.Document"
'' .ActivateAs ClassType:="WordPad.Document"
' .Activate
' DoEvents
' SendKeys "{ESC}"
' ActiveDocument.Activate
' DoEvents
' .Object.SaveAs FileName:=myPCAMAP.Path & "\" & _
' myPCAMAP.InlineShapes(i).OLEFormat.IconLabel & ".txt", _
' FileFormat:=wdFormatText
' End With
' Debug.Print myPCAMAP.InlineShapes(i).OLEFormat.ClassType
myPCAMAP.InlineShapes(i).OLEFormat.Activate
' DoEvents
' SendKeys "{ESC}"
' ActiveDocument.Activate
' DoEvents
' myPCAMAP.InlineShapes(i).OLEFormat.Object.SaveAs FileName:=myPCAMAP.Path & "\" & _
' myPCAMAP.InlineShapes(i).OLEFormat.IconLabel & ".txt", _
' FileFormat:=wdFormatText
' myPCAMAP.InlineShapes(i).OLEFormat.Open
' ActiveDocument.SaveAs FileName:=myPCAMAP.Path & "\" & _
' myPCAMAP.InlineShapes(i).OLEFormat.IconLabel & ".txt", _
' FileFormat:=wdFormatText

' myPCAMAP.InlineShapes(i).OLEFormat.Object.SaveAs FileName:=myPCAMAP.Path & "\" & _
' myPCAMAP.InlineShapes(i).OLEFormat.IconLabel & ".txt"
' myPCAMAP.Activate
End If
End If
Next i

Application.DisplayAlerts = wdAlertsAll

End Sub


I guess I should note that there could be multiple tables in the doc and each table is associated with a memory device. More than one table can be associated with a single memory device. and there can be multiple memory devices called out in a document.

lucas
06-09-2008, 10:31 AM
Excel would be better for this....I know you have a lot of work in it to get it working in Word but still.....all you would have to do is export a delimited text file....