Automatic pasting into Word sometimes doesn't work

September 2, 2015 at 04:48:53
Specs: Windows 8
We're the writers of a small software program, http://www.theftwtranscriber.com/ - it plays media files and automatically inserts timestamps into Word. For example, you can play an mp3, and at 00.00.53, it inserts that timestamp into Word, by putting the timestamp onto the clipboard and pasting it. The problem is that it doesn't work for some users, and we haven't been able to figure out why.

The issue appears to be getting more widespread as people upgrade to Windows 10 and use more recent versions of Word. I have Word 2007 and I have no problems.

Any ideas gratefully received!


See More: Automatic pasting into Word sometimes doesnt work

Report •

#1
September 2, 2015 at 05:19:51
Do you have access to the source code? would you be able to paste some of the code here, particularly the code that creates the MS Word object and then the code that pastes the code.

Report •

#2
September 2, 2015 at 05:34:02
My programmer says that actually the code does some sort of insertion into Word WITHOUT using the clipboard. If that fails (e.g. if Word isn't open), then it DOES use the clipboard. But the main thing is to get this working in Word. The code that inserts the timestamp is this:


void CFTWTView::OpenWord(CString sTimp)
{
BOOL IS_OK;
int step=0;
IS_OK=TRUE;

COleVariant vOpt(DISP_E_PARAMNOTFOUND, VT_ERROR),passx; //For optional args
COleVariant m_True((short)TRUE),m_False((short)FALSE), m_Long((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
COleVariant vTrue((short)TRUE),vFalse((short)FALSE),path_rtf;

COleException *w = new COleException();
try
{

IUnknown* pUnk = NULL ;
CLSID clsid ;
CLSIDFromProgID(L"Word.Application", &clsid) ;
if(::GetActiveObject(clsid, NULL, (IUnknown**)&pUnk) != S_OK)
{
//AfxMessageBox(_T("MS Word not running!")) ;

if(OpenClipboard())
{
EnterCriticalSection(&lockClipBoard);
const size_t newsizew = (sTimp.GetLength() + 1)*2;
char *nstringw = new char[newsizew];
size_t convertedCharsw = 0;
wcstombs_s(&convertedCharsw, nstringw, newsizew, sTimp, _TRUNCATE );

HGLOBAL clipbuffer;
char * buffer;
EmptyClipboard();
clipbuffer = GlobalAlloc(GMEM_DDESHARE, newsizew+1);
buffer = (char*)GlobalLock(clipbuffer);

strcpy(buffer, LPCSTR(nstringw)); delete[] nstringw;

GlobalUnlock(clipbuffer);
SetClipboardData(CF_TEXT,clipbuffer);
CloseClipboard();

GUITHREADINFO gti;
gti.cbSize = sizeof(GUITHREADINFO);
GetGUIThreadInfo(NULL, >i);

::SendMessage(gti.hwndFocus, WM_PASTE, 0, 0);
LeaveCriticalSection(&lockClipBoard);
}

return ;
}

// Get IDispatch
IDispatch *pDispApp ;
COleVariant covOptf12((long)DISP_E_PARAMNOTFOUND, VT_ERROR);
HRESULT hr = pUnk->QueryInterface(IID_IDispatch, (void **)&pDispApp) ;

_Application oApp(pDispApp);
_Document oDoc;

oDoc = oApp.GetActiveDocument();

Selection sSel = oApp.GetSelection();

if (gGlobalData.checkMSBold)
sSel.BoldRun();

if (gGlobalData.checkMSItalic)
sSel.ItalicRun();

sSel.TypeText(sTimp);

if (gGlobalData.checkMSBold)
sSel.BoldRun();

if (gGlobalData.checkMSItalic)
sSel.ItalicRun();
}

catch (COleException* w)
{
IS_OK=FALSE;
w->Delete();
if(step==1)
{
IS_OK=TRUE;
// goto ttry;
}
}
}


Report •

#3
September 2, 2015 at 05:54:26
The problem is that it doesn't work for some users, and we haven't been able to figure out why.

First thing that comes to mind is a possible conflict with an Add-On.

Have you checked to see if those who can not get the software to work
have the same add-on?

There were reported problems with the clipboard not working and the Bluetooth add-in.


MIKE

http://www.skeptic.com/

message edited by mmcconaghy


Report •

Related Solutions

#4
September 2, 2015 at 06:06:12
This is a shot in the dark, but there was a problem
where Skype was causing problems with Copy/Paste.
It was supposedly fixed.
If I remember correctly it was the "Click to Call" function.

MIKE

http://www.skeptic.com/


Report •

#5
September 2, 2015 at 06:09:56
I'm told by the programmer that this is not a clipboard issue. I'm looking into your idea about the add-ins - will get back to you, thanks!

Report •

#6
September 2, 2015 at 06:34:11
In your first message:

it inserts that timestamp into Word, by putting the timestamp onto the clipboard and pasting it.

Now you report:

I'm told by the programmer that this is not a clipboard issue.

In what way is it not a clipboard issue?

Is it just a Paste problem?
Can it be confirmed that the contents of the Copy are in the Clipboard,
but the Paste function is not working?

MIKE

http://www.skeptic.com/


Report •

#7
September 2, 2015 at 06:39:37
re: "it plays media files and automatically inserts timestamps into Word."

Just curious...what is the purpose of this process/software? What is the purpose of keeping track of when a media files is played? Royalties perhaps?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#8
September 2, 2015 at 06:49:25
It seems it's not a clipboard issue, because when I display the Office clipboard, the timestamps do insert (on my computer), but they don't display in the clipboard.

Report •

#9
September 2, 2015 at 08:10:18
the code does some sort of insertion into Word WITHOUT using the clipboard.

Which is what you see on your Win 7 machine where the program works.

You will probably need to get to a machine where the code fails to try a trace the source of the error.

MIKE

http://www.skeptic.com/


Report •

#10
September 2, 2015 at 13:10:11
Agreed. Trying the add-in route first.

Report •

#11
September 9, 2015 at 15:34:49
Looks like this is fixed. My programmer says he "added a resource cleanup after each Word insertion". I'm not sure what that means, but it works! Thanks for responses.

Report •

#12
September 9, 2015 at 18:13:20
Glad you got it working, and thanks for stopping back with an update.

MIKE

http://www.skeptic.com/


Report •

Ask Question