Strange macro problem randomly appears. Copy path to clipboard

Strange macro problem randomly appears. Copy path to clipboard

Anonymous
Not applicable
2,618 Views
8 Replies
Message 1 of 9

Strange macro problem randomly appears. Copy path to clipboard

Anonymous
Not applicable

Hey Guys.

 

I have a macro that copy's the path of the selected part or assembly to the clipboard. I can then paste it in excel, or the browser or add that part in another assembly. I have been using this macro for years without problems.

We upgraded the laptops to Windows 10 4 months ago. the macro still worked perfectly.

Since a couple of days however it works at first, but gives me a strange problem after a while. I have not yet found the trigger for it to start behaving like this.

When I use the macro and then paste it somewhere else, I get 2 question marks inside a square box.

My string inside my macro is still correct. I checked with a msgbox at the end of the macro. So it is a problem with pasting to the clipboard.

 

Anyone have a solution for this? I use this macro all the time, it is reallt slowing me down now.

 

Thank you.

 

what it returns when pasting:

 

2017-03-09_09h16_39.png

 

 

My code:

 

Public Sub copypath()
On Error Resume Next
    Dim oselectcount As Long                                        'Aanpassing
    Dim oprop1 As ComponentOccurrence                               'Zorgt er voor dat in een assembly
    Dim poprop2 As Document                                         'ook properties van onderliggende parts/assemblys
    Dim opropset As Document                                        'ingevuld kunnen worden
    Dim ofilename As String                                         'om filenaam weer te geven op formulier
    
    Set opropset = ThisApplication.ActiveDocument
    oselectcount = ThisApplication.ActiveDocument.SelectSet.Count
    odoctype = ThisApplication.ActiveDocumentType
    
    'kijken of er iets geselecteerd is
    If oselectcount <> 0 Then
        Set oprop1 = ThisApplication.ActiveDocument.SelectSet.Item(1)
        Set oprop2 = oprop1.Definition.Document
        Set opropset = oprop2
        odoctype = oprop1.DefinitionDocumentType
        'Cmdlib.Enabled = True
    End If
    
    ' filenaam weergeven op formulier
    ofilename = opropset.FullFileName
    Set MyData = New DataObject
    
    MyData.SetText ofilename
    MyData.PutInClipboard

 
End Sub

 

0 Likes
Accepted solutions (1)
2,619 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

So I found out that the problem occurs when I open a PDF file.

I tried opening different files, ame result

I tried using 3 different programs to open the PDF files, same result.

 

 

0 Likes
Message 3 of 9

Jef_E
Collaborator
Collaborator

I don't get it, why do you copy paste the value to excel? Why not set the excel value via the excel interop or use the GOEXCEL iLogic functions?



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 4 of 9

Anonymous
Not applicable
Accepted solution

@Jef_E wrote:

I don't get it, why do you copy paste the value to excel? Why not set the excel value via the excel interop or use the GOEXCEL iLogic functions?


Because excel whas just an example. Like I say, I also paste in the browser, or in another assembly or even in a mail. Excel has nothing to do with the macro. Also, as far as my limited knowledge of ilogic goes (correct me if I'm wrong), ilogic is embedded in a part or assembly. That does not help me with this feature.

 

 

Anyway, I just found the solution.

It seems this is a well known bug in windows and alot of people have the same problem.

I also found it is not only triggered by PDF's.

 

Anyway, here is the solution: http://stackoverflow.com/questions/35416662/text-to-clipboard-in-vba-windows-10-issue

 

Hope this helps someone else.

Thx for reading.

 

 

 

0 Likes
Message 5 of 9

Jef_E
Collaborator
Collaborator

I did not specificly pointed to iLogic.

 

If you make a standalone plugin or embedded Addin you should adress objects as they should be. And the proper way to fill values is not copy pasting..

 

For example Sending a email from Inventor does not really sent a email using inventor, you adress outlook to sent information from inventor.

 

Here is just a random sample.. 

        ' Create a outlook object
        Dim oApp As Interop.Outlook._Application
        oApp = New Interop.Outlook.Application

        ' Create a new email message
        Dim oMsg As Interop.Outlook._MailItem
        oMsg = oApp.CreateItem(Interop.Outlook.OlItemType.olMailItem)

        ' Set the email subject
        oMsg.Subject = ("Bug log - New Entry - ID " & AppendToLog() - 1)

        ' Set the email description
        oMsg.Body = "Error found in file: " & Inventor.Document.FullFilePath

        ' Set the email receiver
        oMsg.To = "xxxx@outlook.com"

       ' Send the message
       oMsg.Send()


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
Message 6 of 9

Anonymous
Not applicable

I think you are overcomplicating things, or don't understand what I am trying to do. And to be honest, I don't understand what you are taking about.

I need something to be copy/pasted somewhere else, then I think the best way to do it is to copy/paste it.

And rather then manually selecting a path to file and then pressing CTRL-C, I use the macro. Nothing more to it.

I'm not talking about filling in values, or automated emails. I simply need the path of my selected file on the clipboard.

 

So my question then is, how would you copy the path of a selected file to be pasted anywhere else?

 

PS. I'm not a programmer. I'm trying to learn so thank you for the feedback.

 

 

 

 

0 Likes
Message 7 of 9

Jef_E
Collaborator
Collaborator

I based my feedback on your original post.

 

  1. I have a value (don't really care what it is for now)
  2. I want to have that value in a specific different element (in your example excel)

If I was to customize this, I would not copy paste the value but hold the value as variable in memory and point it to specific object ( in this example excel cell)

 

But the location must be fixed, so If you make handouts for production with a default template you could automate this with all property values even a thumbnail image of the part etc.

 

If the location is not fixed, then you are right, a copy to clipboard would be the best choice. So I might have misinterpreted the question.



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
Message 8 of 9

Anonymous
Not applicable

I never used the term value, nor did I say I want it in a specific different element. Smiley Tongue

 

Did you get 2 posts mixed up? 🙂

 

Anyway, I think we are on the same page now.

thx for the input.

0 Likes
Message 9 of 9

Jef_E
Collaborator
Collaborator

I don't know but the path of a document is a value... The partnumber property has a value.. each object that you can refer to in Inventor has a value... And you stated that you want to paste it into excel.. But lets leave it at that.

 

 



Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes