Solved

How to read filetype in vba word 2007

Posted on 2009-05-05
11
917 Views
Last Modified: 2012-05-06
Hi Experts.
I'm looking for a way to replace the filesearch functionality that was available in vba in Office 2003.  I've looked at Altfilesearch but it doesn't have what I need.

What I need to do is return the filetype from a known file so that I can then complete an action, based on that file type.  I'm looking for microsoft office document imaging file types.  Problem is, the extension will always be .tif, regardless of the actual file type.  Some may be .tif, which is fine.  Others will actually be document imaging files, which I then have to perform an action on.

Any ideas on the way to search the filetype in VBA from Word 2007?  I've been stumped by this one for a while now.
0
Comment
Question by:noclew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 45

Expert Comment

by:aikimark
ID: 24308547
the file type is the extension, isn't it?
0
 

Author Comment

by:noclew
ID: 24308918
Hi there aikmark!  

No.  The filetype is not necessarily the extension.  For instance, I can have a document with an extension of .tif.  Unfortunately, based on how a user has an advanced preference set on MODI, their output will be as an MDI, even though the extension is .tif.  I need to go deeper than just the extension.  The actual type of file does show when the document is opened in the Microsoft Office Document Image Viewer under file>properties>general.  Either MDI or TIFF.

Any thoughts?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 24310413
if you right click on one of these (MDI) files in the Windows explorer, do you see any difference in the file type and file extension?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:noclew
ID: 24310902
Unfortunately, no.  They both read as Document Imaging files in the properties you access through windows explorer.  The properties window within the Microsoft Office Document Image Viewer does show the difference however.
0
 
LVL 45

Assisted Solution

by:aikimark
aikimark earned 500 total points
ID: 24313000
I suspect that the MS Office Document Image Viewer is inspecting the byte configuration of the files to determine the 'file type', and then rendering the image for that type of image file.

Although it is possible to replicate this in VBA, it won't be easy.  
* You will have to determine the various byte patterns you might encounter.
* You will have to efficiently encode these patterns for use by the code.

================
An easier solution might be to use a third-party, including MS, library to help you do this determination.
0
 

Author Comment

by:noclew
ID: 24313980
Thanks for the comments!

Unfortunately, 3rd party is out because of the restrictions in place with that particular IT department.  Byte configuration sounds complicated but it may be the only way I can go.  Are you able to provide me with some sort of sample like you've suggested above?
0
 
LVL 45

Expert Comment

by:aikimark
ID: 24314878
No.

Why not use the Document Image Viewer?  What difference is there between using a Microsoft program and using software from some other vendor?  What restrictions are in place?
0
 

Author Comment

by:noclew
ID: 24315041
Hi there.  
Sorry, the organization uses extremely sensitive, confidential information that involves the general public.  They are about the toughest company I've ever seen when it comes to privacy, system integrity, etc.  They are not open to the inclusion of any type of 3rd party software over and above what has already been approved for use.  It is considered high-risk and would need to go through a very stringent (read years of testing) approval process before being allowed.  I have tight parameters around what I'm permitted to do.  One of those is only using software that is currently approved.  Microsoft Office Document Imaging is currently approved.

Could I use a shell command to open up MODI and then somehow manipulate from there?
Any other ideas or thoughts?
0
 

Author Comment

by:noclew
ID: 24315199
Ok.  Just noticed something interesting.  When I right click, for the true MDI files, the summary properties are unavailable (greyed out).  When I right click on a true TIF file, the summary properties are available, though they may be empty.  Is there a way to query the summary properties for the value?
0
 

Accepted Solution

by:
noclew earned 0 total points
ID: 24316290
Came up with a solution.  A Tiff image produces 1 bit per pixel and an MDI image produces 24 bits per pixel.  So by reading the bits per pixel, I can differentiate between the two types.  In order to read the bits per pixel, I can use the MODI object that is standard.  The below shows an example of how this works.  For this example, I've stored the result in a variable and then displayed it with a msgbox.  However, I could obviously use the result any way I require.  Here it is...

Thanks to aikimark for pointing me in the right direction wth the byte configuration comment!  Points awarded to him.

Sub TestImageProperties()
Dim midoc
  Dim img
  Dim strImageInfo As String
  Set img = CreateObject("modi.document")
  Set midoc = CreateObject("modi.document")
  midoc.create "C:\documents and settings\lainsonj\desktop\tif.tif"
  Set img = midoc.Images(0)
  
  strImageInfo = img.BitsPerPixel
  
  MsgBox strImageInfo
  Set img = Nothing
End Sub

Open in new window

0
 
LVL 45

Expert Comment

by:aikimark
ID: 24316499
I have no object to this request.  

It is the solution I expected and suggested/referenced in comments #24313000 and #24314878.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video teaches the viewer how to align pictures around text while keeping the text properly aligned in the document.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question